@@ -256,6 +256,7 @@ |
||
| 256 | 256 | //Insert callee cdr entry for DID calls |
| 257 | 257 | /** |
| 258 | 258 | * @param boolean $flag_parent |
| 259 | + * @param string $provider_cost |
|
| 259 | 260 | */ |
| 260 | 261 | function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
| 261 | 262 | { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING') |
| 48 | 48 | { |
| 49 | 49 | $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']; |
| 50 | - }else{ |
|
| 50 | + } else{ |
|
| 51 | 51 | $hangup_cause = $dataVariable['hangup_cause']; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -86,10 +86,12 @@ discard block |
||
| 86 | 86 | $actual_calltype = $dataVariable['calltype']; |
| 87 | 87 | |
| 88 | 88 | //Normalize origination and termination rates array |
| 89 | - if(isset($dataVariable['origination_rates'])) |
|
| 90 | - $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
|
| 91 | - if(isset($dataVariable['termination_rates'])) |
|
| 92 | - $termination_rate = normalize_rate($dataVariable['termination_rates']); |
|
| 89 | + if(isset($dataVariable['origination_rates'])) { |
|
| 90 | + $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
|
| 91 | + } |
|
| 92 | + if(isset($dataVariable['termination_rates'])) { |
|
| 93 | + $termination_rate = normalize_rate($dataVariable['termination_rates']); |
|
| 94 | + } |
|
| 93 | 95 | |
| 94 | 96 | //If receiver account id found then explicitly set call direction and call type |
| 95 | 97 | if(isset($dataVariable['receiver_accid'])) |
@@ -441,11 +443,12 @@ discard block |
||
| 441 | 443 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
| 442 | 444 | $counter = $db->run($query_counter); |
| 443 | 445 | $logger->log("GET Counters : " . $query_counter); |
| 444 | - if($counter) |
|
| 445 | - return $counter[0]; |
|
| 446 | - else |
|
| 447 | - return ""; |
|
| 448 | -} |
|
| 446 | + if($counter) { |
|
| 447 | + return $counter[0]; |
|
| 448 | + } else { |
|
| 449 | + return ""; |
|
| 450 | + } |
|
| 451 | + } |
|
| 449 | 452 | |
| 450 | 453 | //Get user info |
| 451 | 454 | function get_accounts($parent_id,$logger, $db) { |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | $dataVariable['call_direction'] = "inbound"; |
| 160 | 160 | $dataVariable['calltype'] = "DID"; |
| 161 | 161 | |
| 162 | - //Override variables if call for DID PSTN |
|
| 163 | - if(isset($dataVariable['caller_did_account_id'])) |
|
| 164 | - { |
|
| 165 | - $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
|
| 166 | - $dataVariable['call_direction'] = "outbound"; |
|
| 167 | - $dataVariable['calltype'] = "STANDARD"; |
|
| 168 | - $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
| 169 | - unset($termination_rate); |
|
| 170 | - unset($provider_cost); |
|
| 171 | - } |
|
| 162 | + //Override variables if call for DID PSTN |
|
| 163 | + if(isset($dataVariable['caller_did_account_id'])) |
|
| 164 | + { |
|
| 165 | + $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
|
| 166 | + $dataVariable['call_direction'] = "outbound"; |
|
| 167 | + $dataVariable['calltype'] = "STANDARD"; |
|
| 168 | + $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
| 169 | + unset($termination_rate); |
|
| 170 | + unset($provider_cost); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | //Generate CDR string for insert query for reseller |
| 317 | 317 | function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
| 318 | 318 | { |
| 319 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
| 319 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
| 320 | 320 | $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
| 321 | 321 | |
| 322 | 322 | return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
@@ -327,27 +327,27 @@ discard block |
||
| 327 | 327 | * @param integer $entity_id |
| 328 | 328 | */ |
| 329 | 329 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
| 330 | - $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
|
| 331 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
| 332 | - $logger->log("Balance update : " . $query); |
|
| 333 | - $db->run($query); |
|
| 330 | + $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
|
| 331 | + $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
| 332 | + $logger->log("Balance update : " . $query); |
|
| 333 | + $db->run($query); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | //Normalize rate string which we are getting from dialplan |
| 337 | 337 | function normalize_rate($dataVariable) |
| 338 | 338 | { |
| 339 | 339 | $rates = urldecode($dataVariable); |
| 340 | - $data = explode("|", $rates); |
|
| 340 | + $data = explode("|", $rates); |
|
| 341 | 341 | |
| 342 | 342 | $newarray = array(); |
| 343 | - foreach ($data as $key => $value) |
|
| 344 | - { |
|
| 345 | - $data1 = explode(":", $value); |
|
| 346 | - foreach ($data1 as $newkey => $newvalue) |
|
| 347 | - { |
|
| 348 | - $newarray[$data1[0]] = $data1[$newkey]; |
|
| 349 | - } |
|
| 350 | - } |
|
| 343 | + foreach ($data as $key => $value) |
|
| 344 | + { |
|
| 345 | + $data1 = explode(":", $value); |
|
| 346 | + foreach ($data1 as $newkey => $newvalue) |
|
| 347 | + { |
|
| 348 | + $newarray[$data1[0]] = $data1[$newkey]; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | 351 | return $newarray; |
| 352 | 352 | } |
| 353 | 353 | |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING') |
| 48 | 48 | { |
| 49 | - $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']; |
|
| 50 | - }else{ |
|
| 49 | + $hangup_cause = isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']; |
|
| 50 | + } else { |
|
| 51 | 51 | $hangup_cause = $dataVariable['hangup_cause']; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | if ($dataVariable['error_cdr'] == '1') |
| 55 | 55 | { |
| 56 | 56 | //Get actual hangup cause |
| 57 | - $hangup_cause= (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']); |
|
| 57 | + $hangup_cause = (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /*#### PATCH FOR ONE WAY AUDIO ####*/ |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | /*#### ************* END *************####*/ |
| 66 | 66 | |
| 67 | 67 | //Don't thing this will be useful anytime. Need to remove it after testing. |
| 68 | - if($hangup_cause == "NONE") |
|
| 68 | + if ($hangup_cause == "NONE") |
|
| 69 | 69 | { |
| 70 | 70 | $hangup_cause = $dataVariable['current_application_data']; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $dataVariable['hangup_cause'] = $hangup_cause; |
| 74 | 74 | |
| 75 | - if ( ($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
| 75 | + if (($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
| 76 | 76 | $dataVariable['billsec'] = 0; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | $actual_calltype = $dataVariable['calltype']; |
| 87 | 87 | |
| 88 | 88 | //Normalize origination and termination rates array |
| 89 | - if(isset($dataVariable['origination_rates'])) |
|
| 89 | + if (isset($dataVariable['origination_rates'])) |
|
| 90 | 90 | $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
| 91 | - if(isset($dataVariable['termination_rates'])) |
|
| 91 | + if (isset($dataVariable['termination_rates'])) |
|
| 92 | 92 | $termination_rate = normalize_rate($dataVariable['termination_rates']); |
| 93 | 93 | |
| 94 | 94 | //If receiver account id found then explicitly set call direction and call type |
| 95 | - if(isset($dataVariable['receiver_accid'])) |
|
| 95 | + if (isset($dataVariable['receiver_accid'])) |
|
| 96 | 96 | { |
| 97 | 97 | $dataVariable['call_direction'] = "outbound"; |
| 98 | 98 | $dataVariable['calltype'] = "STANDARD"; |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | //Check if cusotmer have any package seconds left to use |
| 102 | 102 | if ($actual_duration > 0) |
| 103 | 103 | { |
| 104 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
| 105 | - if(!empty($package_array)) |
|
| 104 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
| 105 | + if ( ! empty($package_array)) |
|
| 106 | 106 | { |
| 107 | 107 | $dataVariable['calltype'] = "FREE"; |
| 108 | - $dataVariable['package_id']= $package_array['package_id']; |
|
| 108 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | //Calculate debit of customer call |
| 113 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
| 113 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
| 114 | 114 | |
| 115 | 115 | //Calculate cost for customer call for provider |
| 116 | - $provider_cost = calc_cost($dataVariable,$termination_rate,$logger,$decimal_points); |
|
| 116 | + $provider_cost = calc_cost($dataVariable, $termination_rate, $logger, $decimal_points); |
|
| 117 | 117 | |
| 118 | 118 | //Calculate parent cost if customer have any parent |
| 119 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
| 120 | - $logger->log("Debit :".$debit ." Cost : ".$cost ." Provider Cost : ".$parent_cost); |
|
| 119 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
| 120 | + $logger->log("Debit :".$debit." Cost : ".$cost." Provider Cost : ".$parent_cost); |
|
| 121 | 121 | |
| 122 | 122 | //Initialize final cost variable to use for billing |
| 123 | 123 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
@@ -125,33 +125,33 @@ discard block |
||
| 125 | 125 | //Outbound call entry for all type of calls |
| 126 | 126 | $logger->log("*********************** OUTBOUND CALL ENTRY START *************"); |
| 127 | 127 | |
| 128 | - $cdr_string = get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger); |
|
| 128 | + $cdr_string = get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger); |
|
| 129 | 129 | |
| 130 | 130 | $query = "INSERT INTO cdrs (uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
| 131 | 131 | $logger->log($query); |
| 132 | 132 | $db->run($query); |
| 133 | 133 | |
| 134 | 134 | //Update customer balance |
| 135 | - if($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
| 135 | + if ($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
| 136 | 136 | { |
| 137 | 137 | update_balance($accountid, $debit, 0, $logger, $db); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | //Update parent or provider balance |
| 141 | - if($parent_cost > 0){ |
|
| 141 | + if ($parent_cost > 0) { |
|
| 142 | 142 | update_balance($termination_rate['PROVIDER'], ($parent_cost * -1), 3, $logger, $db); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | //Resellers CDR entry |
| 146 | 146 | $flag_parent = false; |
| 147 | - insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
| 147 | + insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
| 148 | 148 | |
| 149 | 149 | $logger->log("*********************** OUTBOUND CALL ENTRY END *************"); |
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | //************ ADDING EXTRA ENTRY For local/DID Inbound call **************************** |
| 153 | - $receiver_parentid=0; |
|
| 154 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
| 153 | + $receiver_parentid = 0; |
|
| 154 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
| 155 | 155 | { |
| 156 | 156 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************"); |
| 157 | 157 | |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | $dataVariable['calltype'] = "DID"; |
| 161 | 161 | |
| 162 | 162 | //Override variables if call for DID PSTN |
| 163 | - if(isset($dataVariable['caller_did_account_id'])) |
|
| 163 | + if (isset($dataVariable['caller_did_account_id'])) |
|
| 164 | 164 | { |
| 165 | 165 | $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
| 166 | 166 | $dataVariable['call_direction'] = "outbound"; |
| 167 | 167 | $dataVariable['calltype'] = "STANDARD"; |
| 168 | - $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
| 168 | + $dataVariable['effective_destination_number'] = $dataVariable['sip_to_user']; |
|
| 169 | 169 | unset($termination_rate); |
| 170 | 170 | unset($provider_cost); |
| 171 | 171 | } |
@@ -173,17 +173,17 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | |
| 175 | 175 | //Get call receiver account information |
| 176 | - $receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db); |
|
| 176 | + $receiver_carddata = get_accounts($dataVariable['receiver_accid'], $logger, $db); |
|
| 177 | 177 | $receiver_parentid = $receiver_carddata['reseller_id']; |
| 178 | 178 | |
| 179 | 179 | //For additional cdr entry of receiver |
| 180 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$receiver_parentid,$flag_parent,$dataVariable['receiver_accid'],$logger,$db,$decimal_points); |
|
| 180 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $receiver_parentid, $flag_parent, $dataVariable['receiver_accid'], $logger, $db, $decimal_points); |
|
| 181 | 181 | |
| 182 | 182 | $flag_parent = true; |
| 183 | 183 | $dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid; |
| 184 | 184 | |
| 185 | 185 | //Insert parent reseller cdr |
| 186 | - insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
| 186 | + insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
| 187 | 187 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************"); |
| 188 | 188 | } |
| 189 | 189 | //***************************************************************************************** |
@@ -195,16 +195,16 @@ discard block |
||
| 195 | 195 | * @param string $provider_cost |
| 196 | 196 | * @param boolean $flag_parent |
| 197 | 197 | */ |
| 198 | -function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points) |
|
| 198 | +function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) |
|
| 199 | 199 | { |
| 200 | - while($parentid > 0 ) |
|
| 200 | + while ($parentid > 0) |
|
| 201 | 201 | { |
| 202 | 202 | $logger->log("*************** IN PARENT DATA SECTION ********"); |
| 203 | 203 | $dataVariable['calltype'] = $actual_calltype; |
| 204 | - $carddata = get_accounts($parentid,$logger,$db); |
|
| 204 | + $carddata = get_accounts($parentid, $logger, $db); |
|
| 205 | 205 | $accountid = $carddata['id']; |
| 206 | 206 | |
| 207 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
| 207 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
| 208 | 208 | |
| 209 | 209 | //If receiver account id found then explicitly set call direction and call type |
| 210 | 210 | /*if(isset($dataVariable['receiver_accid'])) |
@@ -214,31 +214,31 @@ discard block |
||
| 214 | 214 | }*/ |
| 215 | 215 | |
| 216 | 216 | //Check if reseller have any package seconds left to use |
| 217 | - if ($actual_duration > 0) { |
|
| 218 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
| 219 | - if(!empty($package_array)) |
|
| 217 | + if ($actual_duration > 0) { |
|
| 218 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
| 219 | + if ( ! empty($package_array)) |
|
| 220 | 220 | { |
| 221 | 221 | $dataVariable['calltype'] = "FREE"; |
| 222 | - $dataVariable['package_id']= $package_array['package_id']; |
|
| 222 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | //Get parent id for cost calculation |
| 227 | 227 | $parentid = $carddata['reseller_id']; |
| 228 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
| 228 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
| 229 | 229 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
| 230 | 230 | |
| 231 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
| 231 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
| 232 | 232 | { |
| 233 | 233 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******"); |
| 234 | 234 | $flag_parent = true; |
| 235 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points); |
|
| 235 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points); |
|
| 236 | 236 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******"); |
| 237 | 237 | return true; |
| 238 | 238 | |
| 239 | - } else{ |
|
| 239 | + } else { |
|
| 240 | 240 | |
| 241 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
| 241 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
| 242 | 242 | |
| 243 | 243 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
| 244 | 244 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
@@ -259,38 +259,38 @@ discard block |
||
| 259 | 259 | /** |
| 260 | 260 | * @param boolean $flag_parent |
| 261 | 261 | */ |
| 262 | -function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
|
| 262 | +function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) |
|
| 263 | 263 | { |
| 264 | 264 | $localVariable = $dataVariable; |
| 265 | 265 | $localVariable['call_direction'] = "inbound"; |
| 266 | 266 | $localVariable['uuid'] = $localVariable['uuid'].$dataVariable['calltype']."_".$accountid; |
| 267 | 267 | |
| 268 | - if($dataVariable['calltype'] == "LOCAL") |
|
| 268 | + if ($dataVariable['calltype'] == "LOCAL") |
|
| 269 | 269 | { |
| 270 | 270 | $origination_rate[$accountid]['CODE'] = $dataVariable['effective_destination_number']; |
| 271 | 271 | $origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype']; |
| 272 | - if($flag_parent == false){ |
|
| 273 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger); |
|
| 274 | - } else{ |
|
| 275 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
| 272 | + if ($flag_parent == false) { |
|
| 273 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger); |
|
| 274 | + } else { |
|
| 275 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
| 276 | 276 | } |
| 277 | - } else{ |
|
| 277 | + } else { |
|
| 278 | 278 | |
| 279 | 279 | $origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']); |
| 280 | - $debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points); |
|
| 280 | + $debit = calc_cost($dataVariable, $origination_rate_did[$accountid], $logger, $decimal_points); |
|
| 281 | 281 | |
| 282 | - if($flag_parent == false){ |
|
| 282 | + if ($flag_parent == false) { |
|
| 283 | 283 | |
| 284 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger); |
|
| 285 | - } else{ |
|
| 286 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
| 284 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger); |
|
| 285 | + } else { |
|
| 286 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if($flag_parent == false) |
|
| 290 | + if ($flag_parent == false) |
|
| 291 | 291 | { |
| 292 | 292 | $query = "INSERT INTO cdrs(uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
| 293 | - } else{ |
|
| 293 | + } else { |
|
| 294 | 294 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
| 295 | 295 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
| 296 | 296 | } |
@@ -306,20 +306,20 @@ discard block |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | //Generate CDR string for insert query for customer. |
| 309 | -function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger) |
|
| 309 | +function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger) |
|
| 310 | 310 | { |
| 311 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
| 312 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
| 313 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'],ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'" ).",".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'"; |
|
| 311 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
| 312 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
| 313 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'], ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'").",".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'"; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | //Generate CDR string for insert query for reseller |
| 317 | -function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
|
| 317 | +function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost) |
|
| 318 | 318 | { |
| 319 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
| 320 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
| 319 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
| 320 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
| 321 | 321 | |
| 322 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
| 322 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | //Update user balance |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
| 330 | 330 | $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
| 331 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
| 332 | - $logger->log("Balance update : " . $query); |
|
| 331 | + $query = "UPDATE accounts SET balance=balance-".$amount." WHERE id=".$user_id; |
|
| 332 | + $logger->log("Balance update : ".$query); |
|
| 333 | 333 | $db->run($query); |
| 334 | 334 | } |
| 335 | 335 | |
@@ -388,46 +388,46 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | if ($billseconds > 0) |
| 390 | 390 | { |
| 391 | - $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60); |
|
| 391 | + $call_cost += (ceil($billseconds / $rates['INC']) * $rates['INC']) * ($rates['COST'] / 60); |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | - $call_cost = number_format($call_cost,$decimal_points); |
|
| 394 | + $call_cost = number_format($call_cost, $decimal_points); |
|
| 395 | 395 | $logger->log("Return cost ".$call_cost); |
| 396 | 396 | return $call_cost; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // get intial package information |
| 400 | -function package_calculation($destination_number,$pricelist_id,$duration,$call_direction,$accountid,$db,$logger) |
|
| 400 | +function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger) |
|
| 401 | 401 | { |
| 402 | 402 | $package_array = array(); |
| 403 | - $custom_destination = number_loop($destination_number,"patterns",$db); |
|
| 403 | + $custom_destination = number_loop($destination_number, "patterns", $db); |
|
| 404 | 404 | |
| 405 | 405 | $query = "SELECT * FROM packages as P inner join package_patterns as PKGPTR on P.id = PKGPTR.package_id WHERE ".$custom_destination." AND status = 0 AND pricelist_id = ".$pricelist_id." ORDER BY LENGTH(PKGPTR.patterns) DESC LIMIT 1"; |
| 406 | 406 | |
| 407 | 407 | $package_info = $db->run($query); |
| 408 | - if($package_info){ |
|
| 408 | + if ($package_info) { |
|
| 409 | 409 | $package_info = $package_info[0]; |
| 410 | 410 | |
| 411 | - if( ($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2") ) { |
|
| 411 | + if (($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2")) { |
|
| 412 | 412 | |
| 413 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
| 413 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
| 414 | 414 | |
| 415 | - if(!$counter_info) { |
|
| 415 | + if ( ! $counter_info) { |
|
| 416 | 416 | $Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info['package_id'].",".$accountid.")"; |
| 417 | - $logger->log("Insert Counters : " . $Insert_query); |
|
| 417 | + $logger->log("Insert Counters : ".$Insert_query); |
|
| 418 | 418 | $db->run($Insert_Query); |
| 419 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
| 419 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
| 420 | 420 | |
| 421 | 421 | } |
| 422 | 422 | //print_r($counter_info); |
| 423 | - if ( $package_info['includedseconds'] > ($counter_info['seconds'] )) { |
|
| 423 | + if ($package_info['includedseconds'] > ($counter_info['seconds'])) { |
|
| 424 | 424 | $availableseconds = $package_info['includedseconds'] - $counter_info['seconds']; |
| 425 | 425 | $freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds; |
| 426 | 426 | $duration = ($availableseconds >= $duration) ? $duration : $availableseconds; |
| 427 | - $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds ). " WHERE id = ". $counter_info['id']; |
|
| 428 | - $logger->log("Update Counters : " . $update_query); |
|
| 427 | + $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds)." WHERE id = ".$counter_info['id']; |
|
| 428 | + $logger->log("Update Counters : ".$update_query); |
|
| 429 | 429 | $db->run($update_query); |
| 430 | - $package_array['package_id']= $package_info['package_id']; |
|
| 430 | + $package_array['package_id'] = $package_info['package_id']; |
|
| 431 | 431 | $package_array['calltype'] = "FREE"; |
| 432 | 432 | } |
| 433 | 433 | } |
@@ -436,21 +436,21 @@ discard block |
||
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // Getting used package minutes in counter table |
| 439 | -function get_counters($accountid,$package_id,$db,$logger) |
|
| 439 | +function get_counters($accountid, $package_id, $db, $logger) |
|
| 440 | 440 | { |
| 441 | 441 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
| 442 | 442 | $counter = $db->run($query_counter); |
| 443 | - $logger->log("GET Counters : " . $query_counter); |
|
| 444 | - if($counter) |
|
| 443 | + $logger->log("GET Counters : ".$query_counter); |
|
| 444 | + if ($counter) |
|
| 445 | 445 | return $counter[0]; |
| 446 | 446 | else |
| 447 | 447 | return ""; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | //Get user info |
| 451 | -function get_accounts($parent_id,$logger, $db) { |
|
| 452 | - $query = "SELECT * FROM accounts WHERE id=" . $parent_id; |
|
| 453 | - $logger->log("GET configuration : " . $query); |
|
| 451 | +function get_accounts($parent_id, $logger, $db) { |
|
| 452 | + $query = "SELECT * FROM accounts WHERE id=".$parent_id; |
|
| 453 | + $logger->log("GET configuration : ".$query); |
|
| 454 | 454 | $res_user = $db->run($query); |
| 455 | 455 | return $res_user[0]; |
| 456 | 456 | } |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | { |
| 461 | 461 | $query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'"; |
| 462 | 462 | $config = $db->run($query); |
| 463 | - $logger->log("GET configuration : " . $query); |
|
| 463 | + $logger->log("GET configuration : ".$query); |
|
| 464 | 464 | return $config[0]; |
| 465 | 465 | } |
| 466 | 466 | |
@@ -468,16 +468,16 @@ discard block |
||
| 468 | 468 | /** |
| 469 | 469 | * @param string $field |
| 470 | 470 | */ |
| 471 | -function number_loop($destination,$field,$db) |
|
| 471 | +function number_loop($destination, $field, $db) |
|
| 472 | 472 | { |
| 473 | - $max_len_prefix = strlen($destination); |
|
| 473 | + $max_len_prefix = strlen($destination); |
|
| 474 | 474 | $number_prefix = '('; |
| 475 | - while ($max_len_prefix > 0) |
|
| 475 | + while ($max_len_prefix > 0) |
|
| 476 | 476 | { |
| 477 | - $number_prefix .= "$field='^".substr($destination,0,$max_len_prefix).".*' OR "; |
|
| 477 | + $number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR "; |
|
| 478 | 478 | $max_len_prefix--; |
| 479 | 479 | } |
| 480 | - $number_prefix .= "$field='^defaultprefix.*')";//echo $number_prefix;exit; |
|
| 480 | + $number_prefix .= "$field='^defaultprefix.*')"; //echo $number_prefix;exit; |
|
| 481 | 481 | return $number_prefix; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -487,6 +487,6 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | function convert_to_gmt($date) |
| 489 | 489 | { |
| 490 | - return gmdate('Y-m-d H:i:s', strtotime($date) ); |
|
| 490 | + return gmdate('Y-m-d H:i:s', strtotime($date)); |
|
| 491 | 491 | } |
| 492 | 492 | ?> |
@@ -115,6 +115,10 @@ |
||
| 115 | 115 | $this->process_invoice($account_value, $start_date, $end_date); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | + /** |
|
| 119 | + * @param string $start_date |
|
| 120 | + * @param string $end_date |
|
| 121 | + */ |
|
| 118 | 122 | function process_invoice($accountdata, $start_date, $end_date) { |
| 119 | 123 | //Get Invoice configuration using single query instead of multiple queries. |
| 120 | 124 | $invoice_conf = array(); |
@@ -24,264 +24,264 @@ |
||
| 24 | 24 | |
| 25 | 25 | class GenerateInvoice extends MX_Controller { |
| 26 | 26 | |
| 27 | - public static $global_config; |
|
| 27 | + public static $global_config; |
|
| 28 | 28 | |
| 29 | - function __construct() { |
|
| 30 | - parent::__construct(); |
|
| 31 | - $this->load->model("db_model"); |
|
| 32 | - $this->load->library("astpp/common"); |
|
| 33 | - $this->load->library('html2pdf'); |
|
| 34 | - ini_set("memory_limit", "2048M"); |
|
| 35 | - ini_set("max_execution_time", "259200"); |
|
| 36 | - $this->get_system_config(); |
|
| 37 | - } |
|
| 29 | + function __construct() { |
|
| 30 | + parent::__construct(); |
|
| 31 | + $this->load->model("db_model"); |
|
| 32 | + $this->load->library("astpp/common"); |
|
| 33 | + $this->load->library('html2pdf'); |
|
| 34 | + ini_set("memory_limit", "2048M"); |
|
| 35 | + ini_set("max_execution_time", "259200"); |
|
| 36 | + $this->get_system_config(); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - function get_system_config() { |
|
| 40 | - $query = $this->db->get("system"); |
|
| 41 | - $config = array(); |
|
| 42 | - $result = $query->result_array(); |
|
| 43 | - foreach ($result as $row) { |
|
| 44 | - $config[$row['name']] = $row['value']; |
|
| 45 | - } |
|
| 46 | - self::$global_config['system_config'] = $config; |
|
| 47 | - } |
|
| 39 | + function get_system_config() { |
|
| 40 | + $query = $this->db->get("system"); |
|
| 41 | + $config = array(); |
|
| 42 | + $result = $query->result_array(); |
|
| 43 | + foreach ($result as $row) { |
|
| 44 | + $config[$row['name']] = $row['value']; |
|
| 45 | + } |
|
| 46 | + self::$global_config['system_config'] = $config; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - function getInvoiceData() { |
|
| 50 | - $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0"); |
|
| 51 | - $query = $this->db_model->getSelect("*", "accounts", $where); |
|
| 52 | - if ($query->num_rows > 0) { |
|
| 53 | - $account_data = $query->result_array(); |
|
| 54 | - foreach ($account_data as $data_key => $account_value) { |
|
| 55 | - $end_date = gmdate("Y-m-d")." 23:59:59"; |
|
| 56 | - $account_value['sweep_id'] = (int)$account_value['sweep_id']; |
|
| 57 | - switch ($account_value['sweep_id']) { |
|
| 58 | - case 0: |
|
| 59 | - $start_date = $this->validate_invoice_date($account_value); |
|
| 60 | - if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
| 61 | - $start_date = gmdate("Y-m-d H:i:s"); |
|
| 62 | - } |
|
| 63 | - $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days")); |
|
| 64 | - $this->Generate_Daily_invoice($account_value, $start_date, $end_date); |
|
| 65 | - break; |
|
| 66 | - case 2: |
|
| 67 | - if (date("d") == $account_value['invoice_day']) { |
|
| 68 | - $start_date = $this->validate_invoice_date($account_value); |
|
| 69 | - if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
| 70 | - $start_date = gmdate("Y-m-d H:i:s"); |
|
| 71 | - } |
|
| 72 | - $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month")); |
|
| 73 | - $this->Generate_Monthly_invoice($account_value, $start_date, $end_date); |
|
| 74 | - } |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - $screen_path = getcwd()."/cron"; |
|
| 79 | - $screen_filename = "Email_Broadcast_".strtotime('now'); |
|
| 80 | - $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S $screen_filename php cron.php BroadcastEmail"; |
|
| 81 | - exec($command); |
|
| 82 | - } |
|
| 83 | - } |
|
| 49 | + function getInvoiceData() { |
|
| 50 | + $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0"); |
|
| 51 | + $query = $this->db_model->getSelect("*", "accounts", $where); |
|
| 52 | + if ($query->num_rows > 0) { |
|
| 53 | + $account_data = $query->result_array(); |
|
| 54 | + foreach ($account_data as $data_key => $account_value) { |
|
| 55 | + $end_date = gmdate("Y-m-d")." 23:59:59"; |
|
| 56 | + $account_value['sweep_id'] = (int)$account_value['sweep_id']; |
|
| 57 | + switch ($account_value['sweep_id']) { |
|
| 58 | + case 0: |
|
| 59 | + $start_date = $this->validate_invoice_date($account_value); |
|
| 60 | + if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
| 61 | + $start_date = gmdate("Y-m-d H:i:s"); |
|
| 62 | + } |
|
| 63 | + $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days")); |
|
| 64 | + $this->Generate_Daily_invoice($account_value, $start_date, $end_date); |
|
| 65 | + break; |
|
| 66 | + case 2: |
|
| 67 | + if (date("d") == $account_value['invoice_day']) { |
|
| 68 | + $start_date = $this->validate_invoice_date($account_value); |
|
| 69 | + if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
| 70 | + $start_date = gmdate("Y-m-d H:i:s"); |
|
| 71 | + } |
|
| 72 | + $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month")); |
|
| 73 | + $this->Generate_Monthly_invoice($account_value, $start_date, $end_date); |
|
| 74 | + } |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + $screen_path = getcwd()."/cron"; |
|
| 79 | + $screen_filename = "Email_Broadcast_".strtotime('now'); |
|
| 80 | + $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S $screen_filename php cron.php BroadcastEmail"; |
|
| 81 | + exec($command); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - function validate_invoice_date($account_value) { |
|
| 86 | - $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date"); |
|
| 87 | - $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation']; |
|
| 88 | - $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date))); |
|
| 89 | - return $last_invoice_date; |
|
| 90 | - } |
|
| 85 | + function validate_invoice_date($account_value) { |
|
| 86 | + $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date"); |
|
| 87 | + $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation']; |
|
| 88 | + $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date))); |
|
| 89 | + return $last_invoice_date; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @param string $start_date |
|
| 94 | - * @param string $end_date |
|
| 95 | - */ |
|
| 96 | - function Generate_Daily_invoice($account_value, $start_date, $end_date) { |
|
| 97 | - // echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date; |
|
| 92 | + /** |
|
| 93 | + * @param string $start_date |
|
| 94 | + * @param string $end_date |
|
| 95 | + */ |
|
| 96 | + function Generate_Daily_invoice($account_value, $start_date, $end_date) { |
|
| 97 | + // echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date; |
|
| 98 | 98 | |
| 99 | - require_once('updateBalance.php'); |
|
| 100 | - $updateBalance = new updateBalance(); |
|
| 101 | - $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
| 102 | - $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
| 103 | - $this->process_invoice($account_value, $start_date, $end_date); |
|
| 104 | - } |
|
| 99 | + require_once('updateBalance.php'); |
|
| 100 | + $updateBalance = new updateBalance(); |
|
| 101 | + $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
| 102 | + $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
| 103 | + $this->process_invoice($account_value, $start_date, $end_date); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @param string $start_date |
|
| 108 | - * @param string $end_date |
|
| 109 | - */ |
|
| 110 | - function Generate_Monthly_invoice($account_value, $start_date, $end_date) { |
|
| 111 | - require_once('updateBalance.php'); |
|
| 112 | - $updateBalance = new updateBalance(); |
|
| 113 | - $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
| 114 | - $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
| 115 | - $this->process_invoice($account_value, $start_date, $end_date); |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * @param string $start_date |
|
| 108 | + * @param string $end_date |
|
| 109 | + */ |
|
| 110 | + function Generate_Monthly_invoice($account_value, $start_date, $end_date) { |
|
| 111 | + require_once('updateBalance.php'); |
|
| 112 | + $updateBalance = new updateBalance(); |
|
| 113 | + $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
| 114 | + $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
| 115 | + $this->process_invoice($account_value, $start_date, $end_date); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - function process_invoice($accountdata, $start_date, $end_date) { |
|
| 119 | - //Get Invoice configuration using single query instead of multiple queries. |
|
| 120 | - $invoice_conf = array(); |
|
| 121 | - $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id']; |
|
| 122 | - $where = "accountid IN ('".$reseller_id."','1')"; |
|
| 123 | - $this->db->select('*'); |
|
| 124 | - $this->db->where($where); |
|
| 125 | - $this->db->order_by('accountid', 'desc'); |
|
| 126 | - $this->db->limit(1); |
|
| 127 | - $invoice_conf = $this->db->get('invoice_conf'); |
|
| 128 | - $invoice_conf = (array)$invoice_conf->first_row(); |
|
| 129 | - /*******************************************************/ |
|
| 130 | - $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']); |
|
| 131 | - if ($last_invoice_ID && $last_invoice_ID > 0) { |
|
| 132 | - $last_invoice_ID = ($last_invoice_ID + 1); |
|
| 133 | - } else { |
|
| 134 | - $last_invoice_ID = $invoice_conf['invoice_start_from']; |
|
| 135 | - } |
|
| 136 | - $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT); |
|
| 137 | - $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date); |
|
| 138 | - if ($invoice_sub_total > 0) { |
|
| 139 | - $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
| 140 | - $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date); |
|
| 141 | - $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
| 142 | - $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
| 143 | - $this->download_invoice($invoiceid, $accountdata, $invoice_conf); |
|
| 144 | - } else { |
|
| 145 | - $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
| 146 | - $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
| 147 | - $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
| 148 | - } |
|
| 149 | - } |
|
| 118 | + function process_invoice($accountdata, $start_date, $end_date) { |
|
| 119 | + //Get Invoice configuration using single query instead of multiple queries. |
|
| 120 | + $invoice_conf = array(); |
|
| 121 | + $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id']; |
|
| 122 | + $where = "accountid IN ('".$reseller_id."','1')"; |
|
| 123 | + $this->db->select('*'); |
|
| 124 | + $this->db->where($where); |
|
| 125 | + $this->db->order_by('accountid', 'desc'); |
|
| 126 | + $this->db->limit(1); |
|
| 127 | + $invoice_conf = $this->db->get('invoice_conf'); |
|
| 128 | + $invoice_conf = (array)$invoice_conf->first_row(); |
|
| 129 | + /*******************************************************/ |
|
| 130 | + $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']); |
|
| 131 | + if ($last_invoice_ID && $last_invoice_ID > 0) { |
|
| 132 | + $last_invoice_ID = ($last_invoice_ID + 1); |
|
| 133 | + } else { |
|
| 134 | + $last_invoice_ID = $invoice_conf['invoice_start_from']; |
|
| 135 | + } |
|
| 136 | + $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT); |
|
| 137 | + $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date); |
|
| 138 | + if ($invoice_sub_total > 0) { |
|
| 139 | + $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
| 140 | + $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date); |
|
| 141 | + $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
| 142 | + $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
| 143 | + $this->download_invoice($invoiceid, $accountdata, $invoice_conf); |
|
| 144 | + } else { |
|
| 145 | + $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
| 146 | + $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
| 147 | + $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - function count_invoice_data($account, $start_date = "", $end_date = "") { |
|
| 152 | - $cdr_query = ""; |
|
| 153 | - $inv_data_query = ""; |
|
| 154 | - $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id']; |
|
| 155 | - $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype"; |
|
| 151 | + function count_invoice_data($account, $start_date = "", $end_date = "") { |
|
| 152 | + $cdr_query = ""; |
|
| 153 | + $inv_data_query = ""; |
|
| 154 | + $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id']; |
|
| 155 | + $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype"; |
|
| 156 | 156 | //echo $cdr_query; |
| 157 | - $cdr_data = $this->db->query($cdr_query); |
|
| 158 | - if ($cdr_data->num_rows > 0) { |
|
| 159 | - $cdr_data = $cdr_data->result_array(); |
|
| 160 | - //echo '<pre>'; print_r($cdr_data); exit; |
|
| 161 | - foreach ($cdr_data as $cdrvalue) { |
|
| 162 | - $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']); |
|
| 163 | - $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0", |
|
| 164 | - "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date); |
|
| 165 | - $this->db->insert("invoice_details", $tempArr); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type != 'FREECALL'"; |
|
| 157 | + $cdr_data = $this->db->query($cdr_query); |
|
| 158 | + if ($cdr_data->num_rows > 0) { |
|
| 159 | + $cdr_data = $cdr_data->result_array(); |
|
| 160 | + //echo '<pre>'; print_r($cdr_data); exit; |
|
| 161 | + foreach ($cdr_data as $cdrvalue) { |
|
| 162 | + $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']); |
|
| 163 | + $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0", |
|
| 164 | + "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date); |
|
| 165 | + $this->db->insert("invoice_details", $tempArr); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type != 'FREECALL'"; |
|
| 169 | 169 | //echo $inv_data_query; |
| 170 | - $invoice_data = $this->db->query($inv_data_query); |
|
| 171 | - if ($invoice_data->num_rows > 0) { |
|
| 172 | - $invoice_data = $invoice_data->result_array(); |
|
| 173 | - foreach ($invoice_data as $data_value) { |
|
| 174 | - if ($data_value['count'] > 0) { |
|
| 175 | - $sub_total = ($data_value['debit'] - $data_value['credit']); |
|
| 176 | - $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']); |
|
| 177 | - return $sub_total; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return "0"; |
|
| 182 | - } |
|
| 170 | + $invoice_data = $this->db->query($inv_data_query); |
|
| 171 | + if ($invoice_data->num_rows > 0) { |
|
| 172 | + $invoice_data = $invoice_data->result_array(); |
|
| 173 | + foreach ($invoice_data as $data_value) { |
|
| 174 | + if ($data_value['count'] > 0) { |
|
| 175 | + $sub_total = ($data_value['debit'] - $data_value['credit']); |
|
| 176 | + $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']); |
|
| 177 | + return $sub_total; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return "0"; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - //Change Order of arguements |
|
| 185 | - function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") { |
|
| 186 | - $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid; |
|
| 187 | - $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type !='PAYMENT'"; |
|
| 188 | - $this->db->query($inv_data_query); |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 184 | + //Change Order of arguements |
|
| 185 | + function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") { |
|
| 186 | + $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid; |
|
| 187 | + $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type !='PAYMENT'"; |
|
| 188 | + $this->db->query($inv_data_query); |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * @param string $last_invoice_ID |
|
| 194 | - */ |
|
| 195 | - function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) { |
|
| 196 | - //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days")); |
|
| 197 | - if ($invoiceconf['interval'] > 0) { |
|
| 198 | - $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
|
| 199 | - } else { |
|
| 200 | - $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days")); |
|
| 201 | - } |
|
| 202 | - // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; |
|
| 203 | - $balance = ($account['credit_limit'] - $account['balance']); |
|
| 204 | - $automatic_flag = self::$global_config['system_config']['automatic_invoice']; |
|
| 192 | + /** |
|
| 193 | + * @param string $last_invoice_ID |
|
| 194 | + */ |
|
| 195 | + function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) { |
|
| 196 | + //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days")); |
|
| 197 | + if ($invoiceconf['interval'] > 0) { |
|
| 198 | + $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
|
| 199 | + } else { |
|
| 200 | + $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days")); |
|
| 201 | + } |
|
| 202 | + // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; |
|
| 203 | + $balance = ($account['credit_limit'] - $account['balance']); |
|
| 204 | + $automatic_flag = self::$global_config['system_config']['automatic_invoice']; |
|
| 205 | 205 | if ($automatic_flag == 1) { |
| 206 | - $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
| 207 | - $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance); |
|
| 206 | + $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
| 207 | + $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance); |
|
| 208 | 208 | } else { |
| 209 | - $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
| 210 | - $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1); |
|
| 209 | + $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
| 210 | + $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1); |
|
| 211 | 211 | } |
| 212 | - // echo "<pre>"; print_r($invoice_data); exit; |
|
| 213 | - $this->db->insert("invoices", $invoice_data); |
|
| 214 | - $invoiceid = $this->db->insert_id(); |
|
| 212 | + // echo "<pre>"; print_r($invoice_data); exit; |
|
| 213 | + $this->db->insert("invoices", $invoice_data); |
|
| 214 | + $invoiceid = $this->db->insert_id(); |
|
| 215 | 215 | if ($automatic_flag == 0) { |
| 216 | - $this->download_invoice($invoiceid, $account, $invoiceconf); |
|
| 216 | + $this->download_invoice($invoiceid, $account, $invoiceconf); |
|
| 217 | + } |
|
| 218 | + return $invoiceid; |
|
| 217 | 219 | } |
| 218 | - return $invoiceid; |
|
| 219 | - } |
|
| 220 | 220 | |
| 221 | - function set_invoice_total($invoiceid, $accountid) { |
|
| 222 | - $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL")); |
|
| 223 | - $query = $query->result_array(); |
|
| 224 | - $sub_total = $query["0"]["total"]; |
|
| 225 | - $updateArr = array("amount" => $sub_total); |
|
| 226 | - $this->db->where(array("id" => $invoiceid)); |
|
| 227 | - $this->db->update("invoices", $updateArr); |
|
| 221 | + function set_invoice_total($invoiceid, $accountid) { |
|
| 222 | + $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL")); |
|
| 223 | + $query = $query->result_array(); |
|
| 224 | + $sub_total = $query["0"]["total"]; |
|
| 225 | + $updateArr = array("amount" => $sub_total); |
|
| 226 | + $this->db->where(array("id" => $invoiceid)); |
|
| 227 | + $this->db->update("invoices", $updateArr); |
|
| 228 | 228 | |
| 229 | - $updateArr = array("balance" => "0.00"); |
|
| 230 | - $this->db->where(array("id" => $accountid)); |
|
| 231 | - $this->db->update("accounts", $updateArr); |
|
| 229 | + $updateArr = array("balance" => "0.00"); |
|
| 230 | + $this->db->where(array("id" => $accountid)); |
|
| 231 | + $this->db->update("accounts", $updateArr); |
|
| 232 | 232 | |
| 233 | - return true; |
|
| 234 | - } |
|
| 233 | + return true; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - function download_invoice($invoiceid, $accountdata, $invoice_conf) { |
|
| 237 | - $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid)); |
|
| 238 | - $invoicedata = $invoicedata->result_array(); |
|
| 239 | - $invoicedata = $invoicedata[0]; |
|
| 240 | - $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 241 | - $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 242 | - $this->common->get_invoice_template($invoicedata, $accountdata, false); |
|
| 243 | - if ($invoice_conf['invoice_notification']) { |
|
| 244 | - $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata); |
|
| 245 | - } |
|
| 246 | - } |
|
| 236 | + function download_invoice($invoiceid, $accountdata, $invoice_conf) { |
|
| 237 | + $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid)); |
|
| 238 | + $invoicedata = $invoicedata->result_array(); |
|
| 239 | + $invoicedata = $invoicedata[0]; |
|
| 240 | + $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 241 | + $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf"; |
|
| 242 | + $this->common->get_invoice_template($invoicedata, $accountdata, false); |
|
| 243 | + if ($invoice_conf['invoice_notification']) { |
|
| 244 | + $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * @param string $FilePath |
|
| 250 | - * @param string $Filenm |
|
| 251 | - */ |
|
| 252 | - function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) { |
|
| 253 | - $TemplateData = array(); |
|
| 254 | - $where = array('name' => 'email_new_invoice'); |
|
| 255 | - $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where); |
|
| 256 | - foreach ($EmailTemplate->result_array() as $TemplateVal) { |
|
| 257 | - $TemplateData = $TemplateVal; |
|
| 258 | - $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']); |
|
| 259 | - $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']); |
|
| 260 | - $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']); |
|
| 261 | - $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']); |
|
| 262 | - $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']); |
|
| 248 | + /** |
|
| 249 | + * @param string $FilePath |
|
| 250 | + * @param string $Filenm |
|
| 251 | + */ |
|
| 252 | + function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) { |
|
| 253 | + $TemplateData = array(); |
|
| 254 | + $where = array('name' => 'email_new_invoice'); |
|
| 255 | + $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where); |
|
| 256 | + foreach ($EmailTemplate->result_array() as $TemplateVal) { |
|
| 257 | + $TemplateData = $TemplateVal; |
|
| 258 | + $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']); |
|
| 259 | + $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']); |
|
| 260 | + $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']); |
|
| 261 | + $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']); |
|
| 262 | + $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']); |
|
| 263 | 263 | |
| 264 | - $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']); |
|
| 265 | - $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']); |
|
| 266 | - $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']); |
|
| 267 | - $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']); |
|
| 268 | - $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']); |
|
| 269 | - } |
|
| 270 | - $dir_path = getcwd()."/attachments/"; |
|
| 271 | - $path = $dir_path.$Filenm; |
|
| 272 | - $command = "cp ".$FilePath." ".$path; |
|
| 273 | - exec($command); |
|
| 274 | - $email_array = array('accountid' => $AccountData['id'], |
|
| 275 | - 'subject' => $TemplateData['subject'], |
|
| 276 | - 'body' => $TemplateData['template'], |
|
| 277 | - 'from' => $invoice_conf['emailaddress'], |
|
| 278 | - 'to' => $AccountData['email'], |
|
| 279 | - 'status' => "1", |
|
| 280 | - 'attachment' => $Filenm, |
|
| 281 | - 'template' => ''); |
|
| 282 | - //echo "<pre>"; print_r($TemplateData); exit; |
|
| 283 | - $this->db->insert("mail_details", $email_array); |
|
| 284 | - } |
|
| 264 | + $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']); |
|
| 265 | + $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']); |
|
| 266 | + $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']); |
|
| 267 | + $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']); |
|
| 268 | + $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']); |
|
| 269 | + } |
|
| 270 | + $dir_path = getcwd()."/attachments/"; |
|
| 271 | + $path = $dir_path.$Filenm; |
|
| 272 | + $command = "cp ".$FilePath." ".$path; |
|
| 273 | + exec($command); |
|
| 274 | + $email_array = array('accountid' => $AccountData['id'], |
|
| 275 | + 'subject' => $TemplateData['subject'], |
|
| 276 | + 'body' => $TemplateData['template'], |
|
| 277 | + 'from' => $invoice_conf['emailaddress'], |
|
| 278 | + 'to' => $AccountData['email'], |
|
| 279 | + 'status' => "1", |
|
| 280 | + 'attachment' => $Filenm, |
|
| 281 | + 'template' => ''); |
|
| 282 | + //echo "<pre>"; print_r($TemplateData); exit; |
|
| 283 | + $this->db->insert("mail_details", $email_array); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | } |
| 287 | 287 | |
@@ -43,6 +43,10 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | + /** |
|
| 47 | + * @param string $startdate |
|
| 48 | + * @param string $enddate |
|
| 49 | + */ |
|
| 46 | 50 | function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) { |
| 47 | 51 | // Defined Original Sweep it for calculation start date for first time. |
| 48 | 52 | $accountinfo['original_sweep_id'] = $accountinfo['sweep_id']; |
@@ -101,6 +105,10 @@ discard block |
||
| 101 | 105 | } |
| 102 | 106 | } |
| 103 | 107 | |
| 108 | + /** |
|
| 109 | + * @param string $startdate |
|
| 110 | + * @param string $enddate |
|
| 111 | + */ |
|
| 104 | 112 | function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) { |
| 105 | 113 | $dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"])); |
| 106 | 114 | $AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id']; |
@@ -225,6 +233,7 @@ discard block |
||
| 225 | 233 | |
| 226 | 234 | /** |
| 227 | 235 | * @param string $todate |
| 236 | + * @param string $invoicedate |
|
| 228 | 237 | */ |
| 229 | 238 | function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) { |
| 230 | 239 | $invoiceid = 0; |
@@ -24,271 +24,271 @@ |
||
| 24 | 24 | |
| 25 | 25 | class UpdateBalance extends MX_Controller { |
| 26 | 26 | |
| 27 | - public $account_arr = array(); |
|
| 28 | - public $currentdate = ''; |
|
| 27 | + public $account_arr = array(); |
|
| 28 | + public $currentdate = ''; |
|
| 29 | 29 | |
| 30 | - function __construct() { |
|
| 31 | - parent::__construct(); |
|
| 32 | - $this->load->model("db_model"); |
|
| 33 | - $this->load->model("common_model"); |
|
| 34 | - $this->load->library("astpp/common"); |
|
| 35 | - $this->currentdate = gmdate('Y-m-d H:i:s'); |
|
| 36 | - } |
|
| 30 | + function __construct() { |
|
| 31 | + parent::__construct(); |
|
| 32 | + $this->load->model("db_model"); |
|
| 33 | + $this->load->model("common_model"); |
|
| 34 | + $this->load->library("astpp/common"); |
|
| 35 | + $this->currentdate = gmdate('Y-m-d H:i:s'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - function GetUpdateBalance() { |
|
| 39 | - $accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0")); |
|
| 40 | - foreach ($accounts_data as $account_val) { |
|
| 41 | - $this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s")); |
|
| 42 | - $this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s")); |
|
| 43 | - } |
|
| 44 | - } |
|
| 38 | + function GetUpdateBalance() { |
|
| 39 | + $accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0")); |
|
| 40 | + foreach ($accounts_data as $account_val) { |
|
| 41 | + $this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s")); |
|
| 42 | + $this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s")); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) { |
|
| 46 | + function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) { |
|
| 47 | 47 | // Defined Original Sweep it for calculation start date for first time. |
| 48 | - $accountinfo['original_sweep_id'] = $accountinfo['sweep_id']; |
|
| 49 | - $invoiceid = 0; |
|
| 48 | + $accountinfo['original_sweep_id'] = $accountinfo['sweep_id']; |
|
| 49 | + $invoiceid = 0; |
|
| 50 | 50 | |
| 51 | - // Check Charge is applied that is for first time or already calculated before |
|
| 51 | + // Check Charge is applied that is for first time or already calculated before |
|
| 52 | 52 | |
| 53 | - $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='".gmdate("Y-m-d H:i:s")."')"; |
|
| 54 | - $this->db->where('accountid', $accountinfo['id']); |
|
| 55 | - $this->db->where($where); |
|
| 56 | - $this->db->select('*'); |
|
| 57 | - $account_charges = $this->db->get('charge_to_account'); |
|
| 58 | - if ($account_charges->num_rows() > 0) { |
|
| 59 | - $accountchargs = $account_charges->result_array(); |
|
| 53 | + $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='".gmdate("Y-m-d H:i:s")."')"; |
|
| 54 | + $this->db->where('accountid', $accountinfo['id']); |
|
| 55 | + $this->db->where($where); |
|
| 56 | + $this->db->select('*'); |
|
| 57 | + $account_charges = $this->db->get('charge_to_account'); |
|
| 58 | + if ($account_charges->num_rows() > 0) { |
|
| 59 | + $accountchargs = $account_charges->result_array(); |
|
| 60 | 60 | |
| 61 | - foreach ($accountchargs as $accharges) { |
|
| 62 | - //Get information from database of active charges. |
|
| 63 | - $charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0")); |
|
| 64 | - if ($charge_data && ! empty($charge_data)) { |
|
| 65 | - $charge_data = $charge_data[0]; |
|
| 66 | - //Get Start Date of Charge |
|
| 67 | - $charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ? |
|
| 68 | - date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) : $accharges["assign_date"]; |
|
| 69 | - if ($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day'] < gmdate("d", strtotime($accharges['assign_date'])))) { |
|
| 70 | - $charge_upto = date("Y-m-".$accountinfo['invoice_day']." H:i:s", strtotime($accharges["assign_date"])); |
|
| 71 | - } |
|
| 72 | - //Overwrite Billing scehdule of customer assign proper charge |
|
| 73 | - if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) { |
|
| 74 | - $accountinfo['sweep_id'] = $charge_data['sweep_id']; |
|
| 75 | - } |
|
| 76 | - //IF its already assigned before invoice start date then no need to applied same charge one more time |
|
| 77 | - if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) { |
|
| 78 | - $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 79 | - if ($Manualflg) { |
|
| 80 | - $todate = gmdate("Y-m-d H:i:s", strtotime($enddate)); |
|
| 81 | - } else { |
|
| 82 | - $todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 83 | - } |
|
| 84 | - /* |
|
| 61 | + foreach ($accountchargs as $accharges) { |
|
| 62 | + //Get information from database of active charges. |
|
| 63 | + $charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0")); |
|
| 64 | + if ($charge_data && ! empty($charge_data)) { |
|
| 65 | + $charge_data = $charge_data[0]; |
|
| 66 | + //Get Start Date of Charge |
|
| 67 | + $charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ? |
|
| 68 | + date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) : $accharges["assign_date"]; |
|
| 69 | + if ($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day'] < gmdate("d", strtotime($accharges['assign_date'])))) { |
|
| 70 | + $charge_upto = date("Y-m-".$accountinfo['invoice_day']." H:i:s", strtotime($accharges["assign_date"])); |
|
| 71 | + } |
|
| 72 | + //Overwrite Billing scehdule of customer assign proper charge |
|
| 73 | + if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) { |
|
| 74 | + $accountinfo['sweep_id'] = $charge_data['sweep_id']; |
|
| 75 | + } |
|
| 76 | + //IF its already assigned before invoice start date then no need to applied same charge one more time |
|
| 77 | + if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) { |
|
| 78 | + $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 79 | + if ($Manualflg) { |
|
| 80 | + $todate = gmdate("Y-m-d H:i:s", strtotime($enddate)); |
|
| 81 | + } else { |
|
| 82 | + $todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 83 | + } |
|
| 84 | + /* |
|
| 85 | 85 | * Add assign_date and charge_upto variable for calculation purpose. |
| 86 | 86 | */ |
| 87 | - $itemArr = array('description' => $charge_data['description'], |
|
| 88 | - 'item_id' => $charge_data['id'], |
|
| 89 | - "type" => "SUBCHRG", |
|
| 90 | - "cycle" => $charge_data["sweep_id"], |
|
| 91 | - "assign_date"=>$accharges['assign_date'], |
|
| 92 | - "charge_upto"=>$accharges['charge_upto']); |
|
| 87 | + $itemArr = array('description' => $charge_data['description'], |
|
| 88 | + 'item_id' => $charge_data['id'], |
|
| 89 | + "type" => "SUBCHRG", |
|
| 90 | + "cycle" => $charge_data["sweep_id"], |
|
| 91 | + "assign_date"=>$accharges['assign_date'], |
|
| 92 | + "charge_upto"=>$accharges['charge_upto']); |
|
| 93 | 93 | //Add a new arguement ($accharges) which have all information of charges. |
| 94 | - $lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]); |
|
| 95 | - if ($lastdate) { |
|
| 96 | - $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"])); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 94 | + $lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]); |
|
| 95 | + if ($lastdate) { |
|
| 96 | + $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"])); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) { |
|
| 105 | - $dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"])); |
|
| 106 | - $AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id']; |
|
| 107 | - $AccountDATA['sweep_id'] = '2'; |
|
| 108 | - if ($dids_data) { |
|
| 109 | - foreach ($dids_data as $did_value) { |
|
| 110 | - $charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"]; |
|
| 104 | + function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) { |
|
| 105 | + $dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"])); |
|
| 106 | + $AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id']; |
|
| 107 | + $AccountDATA['sweep_id'] = '2'; |
|
| 108 | + if ($dids_data) { |
|
| 109 | + foreach ($dids_data as $did_value) { |
|
| 110 | + $charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"]; |
|
| 111 | 111 | |
| 112 | - if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) { |
|
| 113 | - $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 114 | - if ($Manualflg) { |
|
| 115 | - $todate = gmdate("Y-m-d H:i:s", strtotime($enddate)); |
|
| 116 | - } else { |
|
| 117 | - $todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"])); |
|
| 118 | - } |
|
| 119 | - $itemArr = array('description' => $did_value['number'], |
|
| 120 | - 'item_id' => $did_value['id'], |
|
| 121 | - "type" => "DIDCHRG", |
|
| 122 | - "cycle" => "2", |
|
| 123 | - "assign_date"=>$did_value['assign_date'], |
|
| 124 | - "charge_upto"=>$did_value['charge_upto']); |
|
| 125 | - if ($did_value['parent_id'] > 0) { |
|
| 126 | - $parent_id = $did_value['parent_id']; |
|
| 127 | - while ($parent_id != 0) { |
|
| 128 | - $reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number'])); |
|
| 129 | - $reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id)); |
|
| 130 | - $reseller_acc_data = $reseller_acc_data['0']; |
|
| 131 | - $reseller_acc_data['sweep_id'] = '2'; |
|
| 132 | - $reseller_dids = $reseller_dids[0]; |
|
| 133 | - if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) { |
|
| 134 | - //Apply charges to resellers customers. |
|
| 135 | - $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
|
| 136 | - if ($lastdate) |
|
| 137 | - $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 138 | - } else { |
|
| 139 | - //Apply charges to Resellers. |
|
| 140 | - $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
|
| 141 | - if ($lastdate) |
|
| 142 | - $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 143 | - } |
|
| 144 | - $parent_id = $reseller_dids['parent_id']; |
|
| 145 | - } |
|
| 146 | - } |
|
| 112 | + if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) { |
|
| 113 | + $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto)); |
|
| 114 | + if ($Manualflg) { |
|
| 115 | + $todate = gmdate("Y-m-d H:i:s", strtotime($enddate)); |
|
| 116 | + } else { |
|
| 117 | + $todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"])); |
|
| 118 | + } |
|
| 119 | + $itemArr = array('description' => $did_value['number'], |
|
| 120 | + 'item_id' => $did_value['id'], |
|
| 121 | + "type" => "DIDCHRG", |
|
| 122 | + "cycle" => "2", |
|
| 123 | + "assign_date"=>$did_value['assign_date'], |
|
| 124 | + "charge_upto"=>$did_value['charge_upto']); |
|
| 125 | + if ($did_value['parent_id'] > 0) { |
|
| 126 | + $parent_id = $did_value['parent_id']; |
|
| 127 | + while ($parent_id != 0) { |
|
| 128 | + $reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number'])); |
|
| 129 | + $reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id)); |
|
| 130 | + $reseller_acc_data = $reseller_acc_data['0']; |
|
| 131 | + $reseller_acc_data['sweep_id'] = '2'; |
|
| 132 | + $reseller_dids = $reseller_dids[0]; |
|
| 133 | + if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) { |
|
| 134 | + //Apply charges to resellers customers. |
|
| 135 | + $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
|
| 136 | + if ($lastdate) |
|
| 137 | + $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 138 | + } else { |
|
| 139 | + //Apply charges to Resellers. |
|
| 140 | + $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
|
| 141 | + if ($lastdate) |
|
| 142 | + $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 143 | + } |
|
| 144 | + $parent_id = $reseller_dids['parent_id']; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | // else{ |
| 148 | - $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1"); |
|
| 149 | - if ($lastdate) |
|
| 150 | - $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"])); |
|
| 148 | + $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1"); |
|
| 149 | + if ($lastdate) |
|
| 150 | + $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"])); |
|
| 151 | 151 | // } |
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * @param string $fromdate |
|
| 159 | - * @param string $todate |
|
| 160 | - */ |
|
| 161 | - function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") { |
|
| 162 | - $lastdate = false; |
|
| 163 | - $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month"; |
|
| 164 | - $last_invoice_date = $this->common->get_invoice_date("invoice_date", $AccountDATA['id'], $AccountDATA['reseller_id']); |
|
| 165 | - //Below variable gives date based on assign or creation or monthly user billing day |
|
| 166 | - $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day'] < gmdate("d", strtotime($itemArr['assign_date'])))) ? date("Y-m-".$AccountDATA['invoice_day']." 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation'])))); |
|
| 167 | - $last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate; |
|
| 168 | - $Charges_date_range = array(); |
|
| 169 | - $prorate_array = array(); |
|
| 170 | - $daylen = 60 * 60 * 24; |
|
| 171 | - /*Get assign day and billing day for postpaid monthly user. |
|
| 157 | + /** |
|
| 158 | + * @param string $fromdate |
|
| 159 | + * @param string $todate |
|
| 160 | + */ |
|
| 161 | + function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") { |
|
| 162 | + $lastdate = false; |
|
| 163 | + $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month"; |
|
| 164 | + $last_invoice_date = $this->common->get_invoice_date("invoice_date", $AccountDATA['id'], $AccountDATA['reseller_id']); |
|
| 165 | + //Below variable gives date based on assign or creation or monthly user billing day |
|
| 166 | + $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day'] < gmdate("d", strtotime($itemArr['assign_date'])))) ? date("Y-m-".$AccountDATA['invoice_day']." 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation'])))); |
|
| 167 | + $last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate; |
|
| 168 | + $Charges_date_range = array(); |
|
| 169 | + $prorate_array = array(); |
|
| 170 | + $daylen = 60 * 60 * 24; |
|
| 171 | + /*Get assign day and billing day for postpaid monthly user. |
|
| 172 | 172 | */ |
| 173 | - $assign_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? gmdate("d", strtotime($itemArr['assign_date'])) : 0; |
|
| 174 | - $billing_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? $AccountDATA['invoice_day'] : 0; |
|
| 175 | - //Create an array if charge not applied yet and invoice day is greater than assign_day |
|
| 176 | - if ($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2) { |
|
| 173 | + $assign_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? gmdate("d", strtotime($itemArr['assign_date'])) : 0; |
|
| 174 | + $billing_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? $AccountDATA['invoice_day'] : 0; |
|
| 175 | + //Create an array if charge not applied yet and invoice day is greater than assign_day |
|
| 176 | + if ($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2) { |
|
| 177 | 177 | $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("-1 second", strtotime(date("Y-m-".$AccountDATA['invoice_day']." 00:00:00", strtotime($itemArr["assign_date"]))))); |
| 178 | 178 | $prorate_array[] = array("start_date" => date("Y-m-d H:i:s", strtotime($itemArr['assign_date'])), "end_date" => $last_invoice_date); |
| 179 | 179 | |
| 180 | - } |
|
| 181 | - while (strtotime($last_invoice_date) <= strtotime($todate)) { |
|
| 182 | - $startdate = $last_invoice_date; |
|
| 183 | - $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+".$billing_cycle, strtotime($last_invoice_date))); |
|
| 184 | - $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($startdate))), "end_date" => $last_invoice_date); |
|
| 185 | - } |
|
| 186 | - if ( ! empty($prorate_array)) { |
|
| 187 | - array_pop($Charges_date_range); |
|
| 188 | - $Charges_date_range = array_merge($prorate_array, $Charges_date_range); |
|
| 189 | - } |
|
| 190 | - if ( ! empty($Charges_date_range)) { |
|
| 191 | - foreach ($Charges_date_range as $ChargeVal) { |
|
| 192 | - if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2)) { |
|
| 193 | - $ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date']))); |
|
| 194 | - } |
|
| 195 | - if ( ! empty($itemArr['charge_upto']) && empty($lastdate)) { |
|
| 196 | - $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2) ? $itemArr['assign_date'] : $ChargeVal['start_date']; |
|
| 197 | - } else { |
|
| 198 | - $start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))); |
|
| 199 | - } |
|
| 180 | + } |
|
| 181 | + while (strtotime($last_invoice_date) <= strtotime($todate)) { |
|
| 182 | + $startdate = $last_invoice_date; |
|
| 183 | + $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+".$billing_cycle, strtotime($last_invoice_date))); |
|
| 184 | + $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($startdate))), "end_date" => $last_invoice_date); |
|
| 185 | + } |
|
| 186 | + if ( ! empty($prorate_array)) { |
|
| 187 | + array_pop($Charges_date_range); |
|
| 188 | + $Charges_date_range = array_merge($prorate_array, $Charges_date_range); |
|
| 189 | + } |
|
| 190 | + if ( ! empty($Charges_date_range)) { |
|
| 191 | + foreach ($Charges_date_range as $ChargeVal) { |
|
| 192 | + if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2)) { |
|
| 193 | + $ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date']))); |
|
| 194 | + } |
|
| 195 | + if ( ! empty($itemArr['charge_upto']) && empty($lastdate)) { |
|
| 196 | + $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2) ? $itemArr['assign_date'] : $ChargeVal['start_date']; |
|
| 197 | + } else { |
|
| 198 | + $start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date'])); |
|
| 202 | - $end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate)); |
|
| 203 | - $start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date))); |
|
| 204 | - $temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)))); |
|
| 205 | - $temp_t_date = new DateTime($start_date); |
|
| 206 | - $diff = $temp_f_date->diff($temp_t_date); |
|
| 207 | - $month = (($diff->format('%y') * 12) + $diff->format('%m')); |
|
| 208 | - $temp_charge = $charge; |
|
| 209 | - if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') { |
|
| 210 | - //Calculate Number of days in month from start date |
|
| 211 | - $total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time)); |
|
| 212 | - $days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen); |
|
| 213 | - $chrg_per_day = ($charge / $total_num_of_day); |
|
| 214 | - $temp_charge = ($chrg_per_day * $days_diff); |
|
| 215 | - } |
|
| 201 | + $lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date'])); |
|
| 202 | + $end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate)); |
|
| 203 | + $start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date))); |
|
| 204 | + $temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)))); |
|
| 205 | + $temp_t_date = new DateTime($start_date); |
|
| 206 | + $diff = $temp_f_date->diff($temp_t_date); |
|
| 207 | + $month = (($diff->format('%y') * 12) + $diff->format('%m')); |
|
| 208 | + $temp_charge = $charge; |
|
| 209 | + if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') { |
|
| 210 | + //Calculate Number of days in month from start date |
|
| 211 | + $total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time)); |
|
| 212 | + $days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen); |
|
| 213 | + $chrg_per_day = ($charge / $total_num_of_day); |
|
| 214 | + $temp_charge = ($chrg_per_day * $days_diff); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date'])) { |
|
| 218 | - $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate); |
|
| 219 | - } |
|
| 220 | - // echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>"; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - return $lastdate; |
|
| 224 | - } |
|
| 217 | + if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date'])) { |
|
| 218 | + $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate); |
|
| 219 | + } |
|
| 220 | + // echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>"; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + return $lastdate; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * @param string $todate |
|
| 228 | - */ |
|
| 229 | - function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) { |
|
| 230 | - $invoiceid = 0; |
|
| 231 | - $Bal = "0.00"; |
|
| 232 | - if ($AccountData["posttoexternal"] == 0) { |
|
| 233 | - $reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0; |
|
| 234 | - $where = "accountid IN ('".$reseller_id."','1')"; |
|
| 235 | - $this->db->where($where); |
|
| 236 | - $this->db->select('*'); |
|
| 237 | - $this->db->order_by('accountid', 'desc'); |
|
| 238 | - $this->db->limit(1); |
|
| 239 | - $invoiceconf = $this->db->get('invoice_conf'); |
|
| 240 | - $invoice_conf = (array)$invoiceconf->first_row(); |
|
| 241 | - $last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']); |
|
| 242 | - if ($last_invoiceid && $last_invoiceid > 0) { |
|
| 243 | - $last_invoiceid = ($last_invoiceid + 1); |
|
| 244 | - } else { |
|
| 245 | - $last_invoiceid = $invoice_conf['invoice_start_from']; |
|
| 246 | - } |
|
| 247 | - $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT); |
|
| 248 | - $invoice_prefix = $invoice_conf['invoice_prefix']; |
|
| 249 | - $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days")); |
|
| 226 | + /** |
|
| 227 | + * @param string $todate |
|
| 228 | + */ |
|
| 229 | + function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) { |
|
| 230 | + $invoiceid = 0; |
|
| 231 | + $Bal = "0.00"; |
|
| 232 | + if ($AccountData["posttoexternal"] == 0) { |
|
| 233 | + $reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0; |
|
| 234 | + $where = "accountid IN ('".$reseller_id."','1')"; |
|
| 235 | + $this->db->where($where); |
|
| 236 | + $this->db->select('*'); |
|
| 237 | + $this->db->order_by('accountid', 'desc'); |
|
| 238 | + $this->db->limit(1); |
|
| 239 | + $invoiceconf = $this->db->get('invoice_conf'); |
|
| 240 | + $invoice_conf = (array)$invoiceconf->first_row(); |
|
| 241 | + $last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']); |
|
| 242 | + if ($last_invoiceid && $last_invoiceid > 0) { |
|
| 243 | + $last_invoiceid = ($last_invoiceid + 1); |
|
| 244 | + } else { |
|
| 245 | + $last_invoiceid = $invoice_conf['invoice_start_from']; |
|
| 246 | + } |
|
| 247 | + $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT); |
|
| 248 | + $invoice_prefix = $invoice_conf['invoice_prefix']; |
|
| 249 | + $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days")); |
|
| 250 | 250 | |
| 251 | - $invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date); |
|
| 252 | - $this->db->set('balance', 'balance-'.$charge, FALSE); |
|
| 253 | - $this->db->where('id', $AccountData["id"]); |
|
| 254 | - $this->db->update("accounts"); |
|
| 255 | - $AccountData['balance'] = ($AccountData['balance'] - $charge); |
|
| 256 | - $Bal = $AccountData['balance']; |
|
| 257 | - } else { |
|
| 258 | - $Bal = ($AccountData["credit_limit"] - $AccountData["balance"]); |
|
| 259 | - } |
|
| 260 | - if ($Bal <= 0) { |
|
| 261 | - $this->db->set('status', "1", FALSE); |
|
| 262 | - $this->db->where('id', $AccountData["id"]); |
|
| 263 | - $this->db->update("accounts"); |
|
| 264 | - } |
|
| 265 | - $invoice_item_arr = array("accountid" => $AccountData["id"], |
|
| 266 | - "reseller_id" => $AccountData["reseller_id"], |
|
| 267 | - "description" => trim($description."-".$fromdate." to ".$todate), |
|
| 268 | - "item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid, |
|
| 269 | - "created_date" => trim($invoicedate), |
|
| 270 | - "item_type" => $type |
|
| 271 | - ); |
|
| 272 | - $this->manage_invoice($invoice_item_arr); |
|
| 273 | - } |
|
| 251 | + $invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date); |
|
| 252 | + $this->db->set('balance', 'balance-'.$charge, FALSE); |
|
| 253 | + $this->db->where('id', $AccountData["id"]); |
|
| 254 | + $this->db->update("accounts"); |
|
| 255 | + $AccountData['balance'] = ($AccountData['balance'] - $charge); |
|
| 256 | + $Bal = $AccountData['balance']; |
|
| 257 | + } else { |
|
| 258 | + $Bal = ($AccountData["credit_limit"] - $AccountData["balance"]); |
|
| 259 | + } |
|
| 260 | + if ($Bal <= 0) { |
|
| 261 | + $this->db->set('status', "1", FALSE); |
|
| 262 | + $this->db->where('id', $AccountData["id"]); |
|
| 263 | + $this->db->update("accounts"); |
|
| 264 | + } |
|
| 265 | + $invoice_item_arr = array("accountid" => $AccountData["id"], |
|
| 266 | + "reseller_id" => $AccountData["reseller_id"], |
|
| 267 | + "description" => trim($description."-".$fromdate." to ".$todate), |
|
| 268 | + "item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid, |
|
| 269 | + "created_date" => trim($invoicedate), |
|
| 270 | + "item_type" => $type |
|
| 271 | + ); |
|
| 272 | + $this->manage_invoice($invoice_item_arr); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * @param string $select |
|
| 277 | - * @param string $table |
|
| 278 | - */ |
|
| 279 | - function get_table_data($select, $table, $where) { |
|
| 280 | - $query = $this->db_model->getSelect($select, $table, $where); |
|
| 281 | - if ($query->num_rows > 0) { |
|
| 282 | - $query_result = $query->result_array(); |
|
| 283 | - return $query_result; |
|
| 284 | - } else { |
|
| 285 | - return false; |
|
| 286 | - } |
|
| 287 | - } |
|
| 275 | + /** |
|
| 276 | + * @param string $select |
|
| 277 | + * @param string $table |
|
| 278 | + */ |
|
| 279 | + function get_table_data($select, $table, $where) { |
|
| 280 | + $query = $this->db_model->getSelect($select, $table, $where); |
|
| 281 | + if ($query->num_rows > 0) { |
|
| 282 | + $query_result = $query->result_array(); |
|
| 283 | + return $query_result; |
|
| 284 | + } else { |
|
| 285 | + return false; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - function Manage_Invoice($invoice_item_arr) { |
|
| 290 | - $this->db->insert("invoice_details", $invoice_item_arr); |
|
| 291 | - } |
|
| 289 | + function Manage_Invoice($invoice_item_arr) { |
|
| 290 | + $this->db->insert("invoice_details", $invoice_item_arr); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | 293 | } |
| 294 | 294 | ?> |
@@ -133,22 +133,25 @@ |
||
| 133 | 133 | if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) { |
| 134 | 134 | //Apply charges to resellers customers. |
| 135 | 135 | $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
| 136 | - if ($lastdate) |
|
| 137 | - $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 136 | + if ($lastdate) { |
|
| 137 | + $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 138 | + } |
|
| 138 | 139 | } else { |
| 139 | 140 | //Apply charges to Resellers. |
| 140 | 141 | $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1"); |
| 141 | - if ($lastdate) |
|
| 142 | - $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 142 | + if ($lastdate) { |
|
| 143 | + $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"])); |
|
| 144 | + } |
|
| 143 | 145 | } |
| 144 | 146 | $parent_id = $reseller_dids['parent_id']; |
| 145 | 147 | } |
| 146 | 148 | } |
| 147 | 149 | // else{ |
| 148 | 150 | $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1"); |
| 149 | - if ($lastdate) |
|
| 150 | - $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"])); |
|
| 151 | -// } |
|
| 151 | + if ($lastdate) { |
|
| 152 | + $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"])); |
|
| 153 | + } |
|
| 154 | + // } |
|
| 152 | 155 | } |
| 153 | 156 | } |
| 154 | 157 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @param string $orientation page orientation, same as TCPDF |
| 32 | 32 | * @param string $unit User measure unit, same as TCPDF |
| 33 | - * @param mixed $format The format used for pages, same as TCPDF |
|
| 33 | + * @param string $format The format used for pages, same as TCPDF |
|
| 34 | 34 | * @param boolean $unicode TRUE means that the input text is unicode (default = true) |
| 35 | 35 | * @param String $encoding charset encoding; default is UTF-8 |
| 36 | 36 | * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). |
@@ -1407,7 +1407,6 @@ discard block |
||
| 1407 | 1407 | * set $_myLastPageGroup; |
| 1408 | 1408 | * |
| 1409 | 1409 | * @access public |
| 1410 | - * @param integer $myLastPageGroup; |
|
| 1411 | 1410 | * @param integer $myLastPageGroup |
| 1412 | 1411 | */ |
| 1413 | 1412 | public function setMyLastPageGroup($myLastPageGroup) |
@@ -1430,7 +1429,6 @@ discard block |
||
| 1430 | 1429 | * set $_myLastPageGroupNb; |
| 1431 | 1430 | * |
| 1432 | 1431 | * @access public |
| 1433 | - * @param integer $myLastPageGroupNb; |
|
| 1434 | 1432 | * @param integer $myLastPageGroupNb |
| 1435 | 1433 | */ |
| 1436 | 1434 | public function setMyLastPageGroupNb($myLastPageGroupNb) |
@@ -14,1427 +14,1427 @@ |
||
| 14 | 14 | |
| 15 | 15 | class HTML2PDF_myPdf extends TCPDF |
| 16 | 16 | { |
| 17 | - protected $_footerParam = array(); |
|
| 18 | - protected $_transf = array(); |
|
| 19 | - protected $_myLastPageGroup = null; |
|
| 20 | - protected $_myLastPageGroupNb = 0; |
|
| 21 | - |
|
| 22 | - // used to make a radius with bezier : (4/3 * (sqrt(2) - 1)) |
|
| 23 | - const MY_ARC = 0.5522847498; |
|
| 24 | - |
|
| 25 | - // nb of segment to build a arc with bezier curv |
|
| 26 | - const ARC_NB_SEGMENT = 8; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * class constructor |
|
| 30 | - * |
|
| 31 | - * @param string $orientation page orientation, same as TCPDF |
|
| 32 | - * @param string $unit User measure unit, same as TCPDF |
|
| 33 | - * @param mixed $format The format used for pages, same as TCPDF |
|
| 34 | - * @param boolean $unicode TRUE means that the input text is unicode (default = true) |
|
| 35 | - * @param String $encoding charset encoding; default is UTF-8 |
|
| 36 | - * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). |
|
| 37 | - * @access public |
|
| 38 | - */ |
|
| 39 | - public function __construct( |
|
| 40 | - $orientation = 'P', |
|
| 41 | - $unit = 'mm', |
|
| 42 | - $format = 'A4', |
|
| 43 | - $unicode = true, |
|
| 44 | - $encoding = 'UTF-8', |
|
| 45 | - $diskcache = false) |
|
| 46 | - { |
|
| 47 | - // call the parent constructor |
|
| 48 | - parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache); |
|
| 49 | - |
|
| 50 | - // init the specific parameters used by HTML2PDF |
|
| 51 | - $this->SetCreator(PDF_CREATOR); |
|
| 52 | - $this->SetAutoPageBreak(false, 0); |
|
| 53 | - $this->linestyleCap = '2 J'; |
|
| 54 | - $this->setPrintHeader(false); |
|
| 55 | - $this->jpeg_quality = 90; |
|
| 56 | - |
|
| 57 | - // prepare the automatic footer |
|
| 58 | - $this->SetMyFooter(); |
|
| 59 | - |
|
| 60 | - $this->cMargin = 0; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Set the parameters for the automatic footer |
|
| 65 | - * |
|
| 66 | - * @param boolean $page display the page number |
|
| 67 | - * @param boolean $date display the date |
|
| 68 | - * @param boolean $hour display the hour |
|
| 69 | - * @param boolean $form display a warning abour forms |
|
| 70 | - * @access public |
|
| 71 | - */ |
|
| 72 | - public function SetMyFooter($page = false, $date = false, $hour = false, $form = false) |
|
| 73 | - { |
|
| 74 | - $page = ($page ? true : false); |
|
| 75 | - $date = ($date ? true : false); |
|
| 76 | - $hour = ($hour ? true : false); |
|
| 77 | - $form = ($form ? true : false); |
|
| 78 | - |
|
| 79 | - $this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * This function is call automatically by TCPDF at the end of a page |
|
| 84 | - * It takes no parameters |
|
| 85 | - * |
|
| 86 | - * @access public |
|
| 87 | - */ |
|
| 88 | - public function Footer() |
|
| 89 | - { |
|
| 90 | - // prepare the text from the tranlated text |
|
| 91 | - $txt = ''; |
|
| 92 | - if ($this->_footerParam['form']) { |
|
| 93 | - $txt = (HTML2PDF_locale::get('pdf05')); |
|
| 94 | - } |
|
| 95 | - if ($this->_footerParam['date'] && $this->_footerParam['hour']) { |
|
| 96 | - $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03')); |
|
| 97 | - } |
|
| 98 | - if ($this->_footerParam['date'] && ! $this->_footerParam['hour']) { |
|
| 99 | - $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01')); |
|
| 100 | - } |
|
| 101 | - if ( ! $this->_footerParam['date'] && $this->_footerParam['hour']) { |
|
| 102 | - $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02')); |
|
| 103 | - } |
|
| 104 | - if ($this->_footerParam['page']) { |
|
| 105 | - $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04')); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (strlen($txt) > 0) { |
|
| 109 | - // replace some values |
|
| 110 | - $toReplace = array( |
|
| 111 | - '[[date_d]]' => date('d'), |
|
| 112 | - '[[date_m]]' => date('m'), |
|
| 113 | - '[[date_y]]' => date('Y'), |
|
| 114 | - '[[date_h]]' => date('H'), |
|
| 115 | - '[[date_i]]' => date('i'), |
|
| 116 | - '[[date_s]]' => date('s'), |
|
| 117 | - '[[page_cu]]' => $this->getMyNumPage(), |
|
| 118 | - '[[page_nb]]' => $this->getMyAliasNbPages(), |
|
| 119 | - ); |
|
| 120 | - $txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt); |
|
| 121 | - |
|
| 122 | - // draw the footer |
|
| 123 | - parent::SetY(-11); |
|
| 124 | - $this->SetFont('helvetica', 'I', 8); |
|
| 125 | - $this->Cell(0, 10, $txt, 0, 0, 'R'); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * after cloning a object, we does not want to clone all the front informations |
|
| 131 | - * because it take a lot a time and a lot of memory => we use reference |
|
| 132 | - * |
|
| 133 | - * @param &HTML2PDF_myPdf object |
|
| 134 | - * @param HTML2PDF_myPdf $pdf |
|
| 135 | - * @access public |
|
| 136 | - */ |
|
| 137 | - public function cloneFontFrom(&$pdf) |
|
| 138 | - { |
|
| 139 | - $this->fonts = &$pdf->getFonts(); |
|
| 140 | - $this->FontFiles = &$pdf->getFontFiles(); |
|
| 141 | - $this->diffs = &$pdf->getDiffs(); |
|
| 142 | - $this->fontlist = &$pdf->getFontList(); |
|
| 143 | - $this->numfonts = &$pdf->getNumFonts(); |
|
| 144 | - $this->fontkeys = &$pdf->getFontKeys(); |
|
| 145 | - $this->font_obj_ids = &$pdf->getFontObjIds(); |
|
| 146 | - $this->annotation_fonts = &$pdf->getAnnotFonts(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * multiple public accessor for some private attributs |
|
| 151 | - * used only by cloneFontFrom |
|
| 152 | - * |
|
| 153 | - * @return &array |
|
| 154 | - * @access public |
|
| 155 | - */ |
|
| 156 | - public function &getFonts() |
|
| 157 | - { |
|
| 158 | - return $this->fonts; |
|
| 159 | - } |
|
| 160 | - public function &getFontFiles() |
|
| 161 | - { |
|
| 162 | - return $this->FontFiles; |
|
| 163 | - } |
|
| 164 | - public function &getDiffs() |
|
| 165 | - { |
|
| 166 | - return $this->diffs; |
|
| 167 | - } |
|
| 168 | - public function &getFontList() |
|
| 169 | - { |
|
| 170 | - return $this->fontlist; |
|
| 171 | - } |
|
| 172 | - public function &getNumFonts() |
|
| 173 | - { |
|
| 174 | - return $this->numfonts; |
|
| 175 | - } |
|
| 176 | - public function &getFontKeys() |
|
| 177 | - { |
|
| 178 | - return $this->fontkeys; |
|
| 179 | - } |
|
| 180 | - public function &getFontObjIds() |
|
| 181 | - { |
|
| 182 | - return $this->font_obj_ids; |
|
| 183 | - } |
|
| 184 | - public function &getAnnotFonts() |
|
| 185 | - { |
|
| 186 | - return $this->annotation_fonts; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Verify that a Font is already loaded |
|
| 191 | - * |
|
| 192 | - * @param string Font Key |
|
| 193 | - * @return boolean |
|
| 194 | - * @access public |
|
| 195 | - */ |
|
| 196 | - public function isLoadedFont($fontKey) |
|
| 197 | - { |
|
| 198 | - if (isset($this->fonts[$fontKey])) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if (isset($this->CoreFonts[$fontKey])) { |
|
| 203 | - return true; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Get the Word Spacing |
|
| 211 | - * |
|
| 212 | - * @access public |
|
| 213 | - * @return float word spacing |
|
| 214 | - */ |
|
| 215 | - public function getWordSpacing() |
|
| 216 | - { |
|
| 217 | - return $this->ws; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * set the Word Spacing |
|
| 222 | - * |
|
| 223 | - * @param float word spacing |
|
| 224 | - * @access public |
|
| 225 | - */ |
|
| 226 | - public function setWordSpacing($ws = 0.) |
|
| 227 | - { |
|
| 228 | - $this->ws = $ws; |
|
| 229 | - $this->_out(sprintf('%.3F Tw', $ws * $this->k)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * start to use a rectangular Cliping Path with radius corners |
|
| 234 | - * |
|
| 235 | - * @param float $x (top left corner) |
|
| 236 | - * @param float $y (top left corner) |
|
| 237 | - * @param float $w (x+w = botom rigth corner) |
|
| 238 | - * @param float $h (y+h = botom rigth corner) |
|
| 239 | - * @param array $cornerTL radius of the Top Left corner |
|
| 240 | - * @param array $cornerTR radius of the Top Right corner |
|
| 241 | - * @param array $cornerBL radius of the Bottom Left corner |
|
| 242 | - * @param array $cornerBR radius of the Bottom Right corner |
|
| 243 | - * @access public |
|
| 244 | - */ |
|
| 245 | - public function clippingPathStart( |
|
| 246 | - $x = null, |
|
| 247 | - $y = null, |
|
| 248 | - $w = null, |
|
| 249 | - $h = null, |
|
| 250 | - $cornerTL = null, |
|
| 251 | - $cornerTR = null, |
|
| 252 | - $cornerBL = null, |
|
| 253 | - $cornerBR = null) |
|
| 254 | - { |
|
| 255 | - // init the path |
|
| 256 | - $path = ''; |
|
| 257 | - |
|
| 258 | - // if we have the position and the size of the rectangle, we can proceed |
|
| 259 | - if ($x !== null && $y !== null && $w !== null && $h !== null) { |
|
| 260 | - // the positions of the rectangle's corners |
|
| 261 | - $x1 = $x * $this->k; |
|
| 262 | - $y1 = ($this->h - $y) * $this->k; |
|
| 263 | - |
|
| 264 | - $x2 = ($x + $w) * $this->k; |
|
| 265 | - $y2 = ($this->h - $y) * $this->k; |
|
| 266 | - |
|
| 267 | - $x3 = ($x + $w) * $this->k; |
|
| 268 | - $y3 = ($this->h - $y - $h) * $this->k; |
|
| 269 | - |
|
| 270 | - $x4 = $x * $this->k; |
|
| 271 | - $y4 = ($this->h - $y - $h) * $this->k; |
|
| 272 | - |
|
| 273 | - // if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle |
|
| 274 | - if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) { |
|
| 275 | - // prepare the radius values |
|
| 276 | - if ($cornerTL) { |
|
| 277 | - $cornerTL[0] = $cornerTL[0] * $this->k; |
|
| 278 | - $cornerTL[1] = -$cornerTL[1] * $this->k; |
|
| 279 | - } |
|
| 280 | - if ($cornerTR) { |
|
| 281 | - $cornerTR[0] = $cornerTR[0] * $this->k; |
|
| 282 | - $cornerTR[1] = -$cornerTR[1] * $this->k; |
|
| 283 | - } |
|
| 284 | - if ($cornerBL) { |
|
| 285 | - $cornerBL[0] = $cornerBL[0] * $this->k; |
|
| 286 | - $cornerBL[1] = -$cornerBL[1] * $this->k; |
|
| 287 | - } |
|
| 288 | - if ($cornerBR) { |
|
| 289 | - $cornerBR[0] = $cornerBR[0] * $this->k; |
|
| 290 | - $cornerBR[1] = -$cornerBR[1] * $this->k; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // if TL radius then specific start else (X1,Y1) |
|
| 294 | - if ($cornerTL) { |
|
| 295 | - $path .= sprintf('%.2F %.2F m ', $x1 + $cornerTL[0], $y1); |
|
| 296 | - } else { |
|
| 297 | - $path .= sprintf('%.2F %.2F m ', $x1, $y1); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // if TR radius then line + arc, else line to (X2,Y2) |
|
| 301 | - if ($cornerTR) { |
|
| 302 | - $xt1 = ($x2 - $cornerTR[0]) + $cornerTR[0] * self::MY_ARC; |
|
| 303 | - $yt1 = ($y2 + $cornerTR[1]) - $cornerTR[1]; |
|
| 304 | - $xt2 = ($x2 - $cornerTR[0]) + $cornerTR[0]; |
|
| 305 | - $yt2 = ($y2 + $cornerTR[1]) - $cornerTR[1] * self::MY_ARC; |
|
| 306 | - |
|
| 307 | - $path .= sprintf('%.2F %.2F l ', $x2 - $cornerTR[0], $y2); |
|
| 308 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2 + $cornerTR[1]); |
|
| 309 | - } else { |
|
| 310 | - $path .= sprintf('%.2F %.2F l ', $x2, $y2); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - // if BR radius then line + arc, else line to (X3, Y3) |
|
| 314 | - if ($cornerBR) { |
|
| 315 | - $xt1 = ($x3 - $cornerBR[0]) + $cornerBR[0]; |
|
| 316 | - $yt1 = ($y3 - $cornerBR[1]) + $cornerBR[1] * self::MY_ARC; |
|
| 317 | - $xt2 = ($x3 - $cornerBR[0]) + $cornerBR[0] * self::MY_ARC; |
|
| 318 | - $yt2 = ($y3 - $cornerBR[1]) + $cornerBR[1]; |
|
| 319 | - |
|
| 320 | - $path .= sprintf('%.2F %.2F l ', $x3, $y3 - $cornerBR[1]); |
|
| 321 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3 - $cornerBR[0], $y3); |
|
| 322 | - } else { |
|
| 323 | - $path .= sprintf('%.2F %.2F l ', $x3, $y3); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // if BL radius then line + arc, else line to (X4, Y4) |
|
| 327 | - if ($cornerBL) { |
|
| 328 | - $xt1 = ($x4 + $cornerBL[0]) - $cornerBL[0] * self::MY_ARC; |
|
| 329 | - $yt1 = ($y4 - $cornerBL[1]) + $cornerBL[1]; |
|
| 330 | - $xt2 = ($x4 + $cornerBL[0]) - $cornerBL[0]; |
|
| 331 | - $yt2 = ($y4 - $cornerBL[1]) + $cornerBL[1] * self::MY_ARC; |
|
| 332 | - |
|
| 333 | - $path .= sprintf('%.2F %.2F l ', $x4 + $cornerBL[0], $y4); |
|
| 334 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4 - $cornerBL[1]); |
|
| 335 | - } else { |
|
| 336 | - $path .= sprintf('%.2F %.2F l ', $x4, $y4); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // if RL radius then line + arc |
|
| 340 | - if ($cornerTL) { |
|
| 341 | - $xt1 = ($x1 + $cornerTL[0]) - $cornerTL[0]; |
|
| 342 | - $yt1 = ($y1 + $cornerTL[1]) - $cornerTL[1] * self::MY_ARC; |
|
| 343 | - $xt2 = ($x1 + $cornerTL[0]) - $cornerTL[0] * self::MY_ARC; |
|
| 344 | - $yt2 = ($y1 + $cornerTL[1]) - $cornerTL[1]; |
|
| 345 | - |
|
| 346 | - $path .= sprintf('%.2F %.2F l ', $x1, $y1 + $cornerTL[1]); |
|
| 347 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1 + $cornerTL[0], $y1); |
|
| 348 | - } |
|
| 349 | - } else { |
|
| 350 | - $path .= sprintf('%.2F %.2F m ', $x1, $y1); |
|
| 351 | - $path .= sprintf('%.2F %.2F l ', $x2, $y2); |
|
| 352 | - $path .= sprintf('%.2F %.2F l ', $x3, $y3); |
|
| 353 | - $path .= sprintf('%.2F %.2F l ', $x4, $y4); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // close the path |
|
| 357 | - $path .= ' h W n'; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // using the path as a clipping path |
|
| 361 | - $this->_out('q '.$path.' '); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * stop to use the Cliping Path |
|
| 366 | - * |
|
| 367 | - * @access public |
|
| 368 | - */ |
|
| 369 | - public function clippingPathStop() |
|
| 370 | - { |
|
| 371 | - $this->_out(' Q'); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * draw a filled corner of a border with a external and a internal radius |
|
| 376 | - * /--------+ ext2 |
|
| 377 | - * / | |
|
| 378 | - * / /-------+ int2 |
|
| 379 | - * / / |
|
| 380 | - * | / |
|
| 381 | - * | | |
|
| 382 | - * | | |
|
| 383 | - * ext1 +-+ int1 + cen |
|
| 384 | - * |
|
| 385 | - * @param float $ext1X |
|
| 386 | - * @param float $ext1Y |
|
| 387 | - * @param float $ext2X |
|
| 388 | - * @param float $ext2Y |
|
| 389 | - * @param float $int1X |
|
| 390 | - * @param float $int1Y |
|
| 391 | - * @param float $int2X |
|
| 392 | - * @param float $int2Y |
|
| 393 | - * @param float $cenX |
|
| 394 | - * @param float $cenY |
|
| 395 | - * @access public |
|
| 396 | - */ |
|
| 397 | - public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY) |
|
| 398 | - { |
|
| 399 | - // prepare the coordinates |
|
| 400 | - $ext1X = $ext1X * $this->k; |
|
| 401 | - $ext2X = $ext2X * $this->k; |
|
| 402 | - $int1X = $int1X * $this->k; |
|
| 403 | - $int2X = $int2X * $this->k; |
|
| 404 | - $cenX = $cenX * $this->k; |
|
| 405 | - |
|
| 406 | - $ext1Y = ($this->h - $ext1Y) * $this->k; |
|
| 407 | - $ext2Y = ($this->h - $ext2Y) * $this->k; |
|
| 408 | - $int1Y = ($this->h - $int1Y) * $this->k; |
|
| 409 | - $int2Y = ($this->h - $int2Y) * $this->k; |
|
| 410 | - $cenY = ($this->h - $cenY) * $this->k; |
|
| 411 | - |
|
| 412 | - // init the curve |
|
| 413 | - $path = ''; |
|
| 414 | - |
|
| 415 | - if ($ext1X - $cenX != 0) { |
|
| 416 | - $xt1 = $cenX + ($ext1X - $cenX); |
|
| 417 | - $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC; |
|
| 418 | - $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC; |
|
| 419 | - $yt2 = $cenY + ($ext2Y - $cenY); |
|
| 420 | - } else { |
|
| 421 | - $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC; |
|
| 422 | - $yt1 = $cenY + ($ext1Y - $cenY); |
|
| 423 | - $xt2 = $cenX + ($ext2X - $cenX); |
|
| 424 | - $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC; |
|
| 425 | - } |
|
| 426 | - $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y); |
|
| 427 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y); |
|
| 428 | - |
|
| 429 | - if ($int1X - $cenX != 0) { |
|
| 430 | - $xt1 = $cenX + ($int1X - $cenX) * self::MY_ARC; |
|
| 431 | - $yt1 = $cenY + ($int2Y - $cenY); |
|
| 432 | - $xt2 = $cenX + ($int1X - $cenX); |
|
| 433 | - $yt2 = $cenY + ($int2Y - $cenY) * self::MY_ARC; |
|
| 434 | - } else { |
|
| 435 | - $xt1 = $cenX + ($int2X - $cenX); |
|
| 436 | - $yt1 = $cenY + ($int1Y - $cenY) * self::MY_ARC; |
|
| 437 | - $xt2 = $cenX + ($int2X - $cenX) * self::MY_ARC; |
|
| 438 | - $yt2 = $cenY + ($int1Y - $cenY); |
|
| 439 | - } |
|
| 440 | - $path .= sprintf('%.2F %.2F l ', $int2X, $int2Y); |
|
| 441 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y); |
|
| 442 | - |
|
| 443 | - // draw the curve |
|
| 444 | - $this->_out($path.'f'); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * draw a filled corner of a border with only a external radius |
|
| 449 | - * /--+ ext2 |
|
| 450 | - * / | |
|
| 451 | - * / | |
|
| 452 | - * / | |
|
| 453 | - * | | |
|
| 454 | - * | | |
|
| 455 | - * | | |
|
| 456 | - * ext1 +-----+ int + cen |
|
| 457 | - * |
|
| 458 | - * @param float $ext1X |
|
| 459 | - * @param float $ext1Y |
|
| 460 | - * @param float $ext2X |
|
| 461 | - * @param float $ext2Y |
|
| 462 | - * @param float $intX |
|
| 463 | - * @param float $intY |
|
| 464 | - * @param float $cenX |
|
| 465 | - * @param float $cenY |
|
| 466 | - * @access public |
|
| 467 | - */ |
|
| 468 | - public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY) |
|
| 469 | - { |
|
| 470 | - // prepare the coordinates |
|
| 471 | - $ext1X = $ext1X * $this->k; |
|
| 472 | - $ext2X = $ext2X * $this->k; |
|
| 473 | - $intX = $intX * $this->k; |
|
| 474 | - $cenX = $cenX * $this->k; |
|
| 475 | - |
|
| 476 | - $ext1Y = ($this->h - $ext1Y) * $this->k; |
|
| 477 | - $ext2Y = ($this->h - $ext2Y) * $this->k; |
|
| 478 | - $intY = ($this->h - $intY) * $this->k; |
|
| 479 | - $cenY = ($this->h - $cenY) * $this->k; |
|
| 480 | - |
|
| 481 | - // init the curve |
|
| 482 | - $path = ''; |
|
| 483 | - |
|
| 484 | - if ($ext1X - $cenX != 0) { |
|
| 485 | - $xt1 = $cenX + ($ext1X - $cenX); |
|
| 486 | - $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC; |
|
| 487 | - $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC; |
|
| 488 | - $yt2 = $cenY + ($ext2Y - $cenY); |
|
| 489 | - } else { |
|
| 490 | - $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC; |
|
| 491 | - $yt1 = $cenY + ($ext1Y - $cenY); |
|
| 492 | - $xt2 = $cenX + ($ext2X - $cenX); |
|
| 493 | - $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC; |
|
| 494 | - } |
|
| 495 | - $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y); |
|
| 496 | - $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y); |
|
| 497 | - $path .= sprintf('%.2F %.2F l ', $intX, $intY); |
|
| 498 | - $path .= sprintf('%.2F %.2F l ', $ext1X, $ext1Y); |
|
| 499 | - |
|
| 500 | - // draw the curve |
|
| 501 | - $this->_out($path.'f'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Start a transformation |
|
| 506 | - * |
|
| 507 | - * @access public |
|
| 508 | - */ |
|
| 509 | - public function startTransform() |
|
| 510 | - { |
|
| 511 | - $this->_out('q'); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Stop a transformation |
|
| 516 | - * |
|
| 517 | - * @access public |
|
| 518 | - */ |
|
| 519 | - public function stopTransform() |
|
| 520 | - { |
|
| 521 | - $this->_out('Q'); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * add a Translate transformation |
|
| 526 | - * |
|
| 527 | - * @access public |
|
| 528 | - */ |
|
| 529 | - public function setTranslate($xT, $yT) |
|
| 530 | - { |
|
| 531 | - // Matrix for Translate |
|
| 532 | - $tm[0] = 1; |
|
| 533 | - $tm[1] = 0; |
|
| 534 | - $tm[2] = 0; |
|
| 535 | - $tm[3] = 1; |
|
| 536 | - $tm[4] = $xT * $this->k; |
|
| 537 | - $tm[5] = -$yT * $this->k; |
|
| 538 | - |
|
| 539 | - // apply the Transform Matric |
|
| 540 | - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * add a Rotate transformation |
|
| 545 | - * |
|
| 546 | - * @param float $angle |
|
| 547 | - * @access public |
|
| 548 | - */ |
|
| 549 | - public function setRotation($angle, $xC = null, $yC = null) |
|
| 550 | - { |
|
| 551 | - // if no center, rotate around the current posiition |
|
| 552 | - if ($xC === null) $xC = $this->x; |
|
| 553 | - if ($yC === null) $yC = $this->y; |
|
| 554 | - |
|
| 555 | - // prepare the coordinate |
|
| 556 | - $yC = ($this->h - $yC) * $this->k; |
|
| 557 | - $xC *= $this->k; |
|
| 558 | - |
|
| 559 | - // Matrix for Rotate |
|
| 560 | - $tm[0] = cos(deg2rad($angle)); |
|
| 561 | - $tm[1] = sin(deg2rad($angle)); |
|
| 562 | - $tm[2] = -$tm[1]; |
|
| 563 | - $tm[3] = $tm[0]; |
|
| 564 | - $tm[4] = $xC + $tm[1] * $yC - $tm[0] * $xC; |
|
| 565 | - $tm[5] = $yC - $tm[0] * $yC - $tm[1] * $xC; |
|
| 566 | - |
|
| 567 | - // apply the Transform Matric |
|
| 568 | - $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * we redifine the original SetX method, because we don't want the automatic treatment. |
|
| 573 | - * It is HTML2PDF that make the treatment |
|
| 574 | - * |
|
| 575 | - * @param float $x |
|
| 576 | - * @param boolean $rtloff NOT USED |
|
| 577 | - * @access public |
|
| 578 | - */ |
|
| 579 | - public function SetX($x, $rtloff = false) |
|
| 580 | - { |
|
| 581 | - $this->x = $x; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * we redifine the original SetY method, because we don't want the automatic treatment. |
|
| 586 | - * It is HTML2PDF that make the treatment |
|
| 587 | - * |
|
| 588 | - * @param float $y |
|
| 589 | - * @param boolean $resetx Reset the X position |
|
| 590 | - * @param boolean $rtloff NOT USED |
|
| 591 | - * @access public |
|
| 592 | - */ |
|
| 593 | - public function SetY($y, $resetx = true, $rtloff = false) |
|
| 594 | - { |
|
| 595 | - if ($resetx) |
|
| 596 | - $this->x = $this->lMargin; |
|
| 597 | - |
|
| 598 | - $this->y = $y; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * we redifine the original SetXY method, because we don't want the automatic treatment. |
|
| 603 | - * It is HTML2PDF that make the treatment |
|
| 604 | - * |
|
| 605 | - * @param integer $x |
|
| 606 | - * @param integer $y |
|
| 607 | - * @param boolean $rtloff NOT USED |
|
| 608 | - * @access public |
|
| 609 | - */ |
|
| 610 | - public function SetXY($x, $y, $rtloff = false) |
|
| 611 | - { |
|
| 612 | - $this->x = $x; |
|
| 613 | - $this->y = $y; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it |
|
| 618 | - * |
|
| 619 | - * @param mixed |
|
| 620 | - * @return mixed |
|
| 621 | - * @access public |
|
| 622 | - */ |
|
| 623 | - public function getK() |
|
| 624 | - { |
|
| 625 | - return $this->k; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * @return double |
|
| 630 | - */ |
|
| 631 | - public function getW() |
|
| 632 | - { |
|
| 633 | - return $this->w; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * @return double |
|
| 638 | - */ |
|
| 639 | - public function getH() |
|
| 640 | - { |
|
| 641 | - return $this->h; |
|
| 642 | - } |
|
| 643 | - public function getlMargin() |
|
| 644 | - { |
|
| 645 | - return $this->lMargin; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @return double |
|
| 650 | - */ |
|
| 651 | - public function getrMargin() |
|
| 652 | - { |
|
| 653 | - return $this->rMargin; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * @return double |
|
| 658 | - */ |
|
| 659 | - public function gettMargin() |
|
| 660 | - { |
|
| 661 | - return $this->tMargin; |
|
| 662 | - } |
|
| 663 | - public function getbMargin() |
|
| 664 | - { |
|
| 665 | - return $this->bMargin; |
|
| 666 | - } |
|
| 667 | - public function setbMargin($v) |
|
| 668 | - { |
|
| 669 | - $this->bMargin = $v; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * SVG - Convert a SVG Style in PDF Style |
|
| 674 | - * |
|
| 675 | - * @param array $styles SVG Style |
|
| 676 | - * @return string PDF style |
|
| 677 | - * @access public |
|
| 678 | - */ |
|
| 679 | - public function svgSetStyle($styles) |
|
| 680 | - { |
|
| 681 | - // init the PDF style |
|
| 682 | - $style = ''; |
|
| 683 | - |
|
| 684 | - // Style : fill |
|
| 685 | - if ($styles['fill']) { |
|
| 686 | - $this->setFillColorArray($styles['fill']); |
|
| 687 | - $style .= 'F'; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - // Style : stroke |
|
| 691 | - if ($styles['stroke'] && $styles['stroke-width']) { |
|
| 692 | - $this->SetDrawColorArray($styles['stroke']); |
|
| 693 | - $this->SetLineWidth($styles['stroke-width']); |
|
| 694 | - $style .= 'D'; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - // Style : opacity |
|
| 698 | - if ($styles['fill-opacity']) { |
|
| 699 | - $this->SetAlpha($styles['fill-opacity']); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return $style; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * SVG - make a Rectangle |
|
| 707 | - * |
|
| 708 | - * @param float $x |
|
| 709 | - * @param float $y |
|
| 710 | - * @param float $w |
|
| 711 | - * @param float $h |
|
| 712 | - * @param string $style PDF Style |
|
| 713 | - * @access public |
|
| 714 | - */ |
|
| 715 | - public function svgRect($x, $y, $w, $h, $style) |
|
| 716 | - { |
|
| 717 | - // prepare the 4 corners |
|
| 718 | - $x1 = $x; |
|
| 719 | - $x2 = $x + $w; |
|
| 720 | - $x3 = $x + $w; |
|
| 721 | - $x4 = $x; |
|
| 722 | - |
|
| 723 | - $y1 = $y; |
|
| 724 | - $y2 = $y; |
|
| 725 | - $y3 = $y + $h; |
|
| 726 | - $y4 = $y + $h; |
|
| 727 | - |
|
| 728 | - // get the Closing operator from the PDF Style |
|
| 729 | - if ($style == 'F') $op = 'f'; |
|
| 730 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 731 | - else $op = 'S'; |
|
| 732 | - |
|
| 733 | - // drawing |
|
| 734 | - $this->_Point($x1, $y1, true); |
|
| 735 | - $this->_Line($x2, $y2, true); |
|
| 736 | - $this->_Line($x3, $y3, true); |
|
| 737 | - $this->_Line($x4, $y4, true); |
|
| 738 | - $this->_Line($x1, $y1, true); |
|
| 739 | - $this->_out($op); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * SVG - make a Line |
|
| 744 | - * |
|
| 745 | - * @param float $x1 |
|
| 746 | - * @param float $y1 |
|
| 747 | - * @param float $x2 |
|
| 748 | - * @param float $y2 |
|
| 749 | - * @access public |
|
| 750 | - */ |
|
| 751 | - public function svgLine($x1, $y1, $x2, $y2) |
|
| 752 | - { |
|
| 753 | - // get the Closing operator |
|
| 754 | - $op = 'S'; |
|
| 755 | - |
|
| 756 | - // drawing |
|
| 757 | - $this->_Point($x1, $y1, true); |
|
| 758 | - $this->_Line($x2, $y2, true); |
|
| 759 | - $this->_out($op); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * SVG - make a Ellipse |
|
| 764 | - * |
|
| 765 | - * @param float $x0 x Center |
|
| 766 | - * @param float $y0 y Center |
|
| 767 | - * @param float $rx x radius |
|
| 768 | - * @param float $ry y radius |
|
| 769 | - * @param string $style PDF Style |
|
| 770 | - * @access public |
|
| 771 | - */ |
|
| 772 | - public function svgEllipse($x0, $y0, $rx, $ry, $style) |
|
| 773 | - { |
|
| 774 | - // get the Closing operator from the PDF Style |
|
| 775 | - if ($style == 'F') $op = 'f'; |
|
| 776 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 777 | - else $op = 'S'; |
|
| 778 | - |
|
| 779 | - // drawing |
|
| 780 | - $this->_Arc($x0, $y0, $rx, $ry, 0, 2 * M_PI, true, true, true); |
|
| 781 | - $this->_out($op); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * SVG - make a Advanced Polygone |
|
| 786 | - * |
|
| 787 | - * @param array $actions list of actions |
|
| 788 | - * @param string $style PDF Style |
|
| 789 | - * @access public |
|
| 790 | - */ |
|
| 791 | - public function svgPolygone($actions, $style) |
|
| 792 | - { |
|
| 793 | - // get the Closing operator from the PDF Style |
|
| 794 | - if ($style == 'F') $op = 'f'; |
|
| 795 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 796 | - else $op = 'S'; |
|
| 797 | - |
|
| 798 | - // To save the First action and the last point |
|
| 799 | - $first = array('', 0, 0); |
|
| 800 | - $last = array(0, 0, 0, 0); |
|
| 801 | - |
|
| 802 | - foreach ($actions as $action) { |
|
| 803 | - switch ($action[0]) |
|
| 804 | - { |
|
| 805 | - // Start the Path |
|
| 806 | - case 'M': |
|
| 807 | - case 'm': |
|
| 808 | - $first = $action; |
|
| 809 | - $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y; |
|
| 810 | - $this->_Point($x, $y, true); |
|
| 811 | - break; |
|
| 812 | - |
|
| 813 | - // Close the Path |
|
| 814 | - case 'Z': |
|
| 815 | - case 'z': |
|
| 816 | - $x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y; |
|
| 817 | - $this->_Line($x, $y, true); |
|
| 818 | - break; |
|
| 819 | - |
|
| 820 | - // Make a Line (new point) |
|
| 821 | - case 'L': |
|
| 822 | - $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y; |
|
| 823 | - $this->_Line($x, $y, true); |
|
| 824 | - break; |
|
| 825 | - |
|
| 826 | - // Make a Line (vector from last point) |
|
| 827 | - case 'l': |
|
| 828 | - $x = $last[0] + $action[1]; $y = $last[1] + $action[2]; $xc = $x; $yc = $y; |
|
| 829 | - $this->_Line($x, $y, true); |
|
| 830 | - break; |
|
| 831 | - |
|
| 832 | - // Make a Horizontal Line (new point) |
|
| 833 | - case 'H': |
|
| 834 | - $x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y; |
|
| 835 | - $this->_Line($x, $y, true); |
|
| 836 | - break; |
|
| 837 | - |
|
| 838 | - // Make a Horisontal Line (vector from last point) |
|
| 839 | - case 'h': |
|
| 840 | - $x = $last[0] + $action[1]; $y = $last[1]; $xc = $x; $yc = $y; |
|
| 841 | - $this->_Line($x, $y, true); |
|
| 842 | - break; |
|
| 843 | - |
|
| 844 | - // Make a Vertical Line (new point) |
|
| 845 | - case 'V': |
|
| 846 | - $x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y; |
|
| 847 | - $this->_Line($x, $y, true); |
|
| 848 | - break; |
|
| 849 | - |
|
| 850 | - // Make a Vertical Line (vector from last point) |
|
| 851 | - case 'v': |
|
| 852 | - $x = $last[0]; $y = $last[1] + $action[1]; $xc = $x; $yc = $y; |
|
| 853 | - $this->_Line($x, $y, true); |
|
| 854 | - break; |
|
| 855 | - |
|
| 856 | - // Make a Arc (new point) |
|
| 857 | - case 'A': |
|
| 858 | - $rx = $action[1]; // rx |
|
| 859 | - $ry = $action[2]; // ry |
|
| 860 | - $a = $action[3]; // deviation angle of the axis X |
|
| 861 | - $l = $action[4]; // large-arc-flag |
|
| 862 | - $s = $action[5]; // sweep-flag |
|
| 863 | - $x1 = $last[0]; // begin x |
|
| 864 | - $y1 = $last[1]; // begin y |
|
| 865 | - $x2 = $action[6]; // final x |
|
| 866 | - $y2 = $action[7]; // final y |
|
| 867 | - |
|
| 868 | - $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true); |
|
| 869 | - $x = $x2; $y = $y2; $xc = $x; $yc = $y; |
|
| 870 | - break; |
|
| 871 | - |
|
| 872 | - // Make a Arc (vector from last point) |
|
| 873 | - case 'a': |
|
| 874 | - $rx = $action[1]; // rx |
|
| 875 | - $ry = $action[2]; // ry |
|
| 876 | - $a = $action[3]; // deviation angle of the axis X |
|
| 877 | - $l = $action[4]; // large-arc-flag |
|
| 878 | - $s = $action[5]; // sweep-flag |
|
| 879 | - $x1 = $last[0]; // begin x |
|
| 880 | - $y1 = $last[1]; // begin y |
|
| 881 | - $x2 = $last[0] + $action[6]; // final x |
|
| 882 | - $y2 = $last[1] + $action[7]; // final y |
|
| 883 | - |
|
| 884 | - $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true); |
|
| 885 | - $x = $x2; $y = $y2; $xc = $x; $yc = $y; |
|
| 886 | - break; |
|
| 887 | - |
|
| 888 | - // Make a Bezier Curve (new point) |
|
| 889 | - case 'C': |
|
| 890 | - $x1 = $action[1]; |
|
| 891 | - $y1 = $action[2]; |
|
| 892 | - $x2 = $action[3]; |
|
| 893 | - $y2 = $action[4]; |
|
| 894 | - $xf = $action[5]; |
|
| 895 | - $yf = $action[6]; |
|
| 896 | - $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true); |
|
| 897 | - $x = $xf; $y = $yf; $xc = $x2; $yc = $y2; |
|
| 898 | - break; |
|
| 899 | - |
|
| 900 | - // Make a Bezier Curve (vector from last point) |
|
| 901 | - case 'c': |
|
| 902 | - $x1 = $last[0] + $action[1]; |
|
| 903 | - $y1 = $last[1] + $action[2]; |
|
| 904 | - $x2 = $last[0] + $action[3]; |
|
| 905 | - $y2 = $last[1] + $action[4]; |
|
| 906 | - $xf = $last[0] + $action[5]; |
|
| 907 | - $yf = $last[1] + $action[6]; |
|
| 908 | - $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true); |
|
| 909 | - $x = $xf; $y = $yf; $xc = $x2; $yc = $y2; |
|
| 910 | - break; |
|
| 911 | - |
|
| 912 | - // Unknown Path |
|
| 913 | - default: |
|
| 914 | - throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown'); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - // save the last point |
|
| 918 | - $last = array($x, $y, $xc, $yc); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - // finish the path |
|
| 922 | - $this->_out($op); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * SVG - go to a point |
|
| 927 | - * |
|
| 928 | - * @param float $x |
|
| 929 | - * @param float $y |
|
| 930 | - * @param boolean $trans apply transformation |
|
| 931 | - * @access protected |
|
| 932 | - */ |
|
| 933 | - protected function _Point($x, $y, $trans = false) |
|
| 934 | - { |
|
| 935 | - if ($trans) { |
|
| 936 | - $this->ptTransform($x, $y); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - $this->_out(sprintf('%.2F %.2F m', $x, $y)); |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * SVG - make a line from the last point to (x,y) |
|
| 944 | - * |
|
| 945 | - * @param float $x |
|
| 946 | - * @param float $y |
|
| 947 | - * @param boolean $trans apply transformation |
|
| 948 | - * @access protected |
|
| 949 | - */ |
|
| 950 | - protected function _Line($x, $y, $trans = false) |
|
| 951 | - { |
|
| 952 | - if ($trans) { |
|
| 953 | - $this->ptTransform($x, $y); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - $this->_out(sprintf('%.2F %.2F l', $x, $y)); |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2) |
|
| 961 | - * |
|
| 962 | - * @param float $x1 |
|
| 963 | - * @param float $y1 |
|
| 964 | - * @param float $x2 |
|
| 965 | - * @param float $y2 |
|
| 966 | - * @param float $xf |
|
| 967 | - * @param float $yf |
|
| 968 | - * @param boolean $trans apply transformation |
|
| 969 | - * @access protected |
|
| 970 | - */ |
|
| 971 | - protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false) |
|
| 972 | - { |
|
| 973 | - if ($trans) { |
|
| 974 | - $this->ptTransform($x1, $y1); |
|
| 975 | - $this->ptTransform($x2, $y2); |
|
| 976 | - $this->ptTransform($xf, $yf); |
|
| 977 | - } |
|
| 978 | - $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf)); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * SVG - make a arc with Center, Radius, from angleBegin to angleEnd |
|
| 983 | - * |
|
| 984 | - * @param float $xc |
|
| 985 | - * @param float $yc |
|
| 986 | - * @param float $rx |
|
| 987 | - * @param float $ry |
|
| 988 | - * @param float $angleBegin in radians |
|
| 989 | - * @param float $angleEnd in radians |
|
| 990 | - * @param boolean $direction |
|
| 991 | - * @param boolean $drawFirst, true => add the first point |
|
| 992 | - * @param boolean $trans apply transformation |
|
| 993 | - * @access protected |
|
| 994 | - */ |
|
| 995 | - protected function _Arc( |
|
| 996 | - $xc, |
|
| 997 | - $yc, |
|
| 998 | - $rx, |
|
| 999 | - $ry, |
|
| 1000 | - $angleBegin, |
|
| 1001 | - $angleEnd, |
|
| 1002 | - $direction = true, |
|
| 1003 | - $drawFirst = true, |
|
| 1004 | - $trans = false) |
|
| 1005 | - { |
|
| 1006 | - // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction |
|
| 1007 | - if ( ! $direction) $angleBegin += M_PI * 2.; |
|
| 1008 | - |
|
| 1009 | - // cut in segment to convert in berize curv |
|
| 1010 | - $dt = ($angleEnd - $angleBegin) / self::ARC_NB_SEGMENT; |
|
| 1011 | - $dtm = $dt / 3; |
|
| 1012 | - |
|
| 1013 | - // center of the arc |
|
| 1014 | - $x0 = $xc; $y0 = $yc; |
|
| 1015 | - |
|
| 1016 | - // calculing the first point |
|
| 1017 | - $t1 = $angleBegin; |
|
| 1018 | - $a0 = $x0 + ($rx * cos($t1)); |
|
| 1019 | - $b0 = $y0 + ($ry * sin($t1)); |
|
| 1020 | - $c0 = -$rx * sin($t1); |
|
| 1021 | - $d0 = $ry * cos($t1); |
|
| 1022 | - |
|
| 1023 | - // if drawFirst => draw the first point |
|
| 1024 | - if ($drawFirst) { |
|
| 1025 | - $this->_Point($a0, $b0, $trans); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - // foreach segment |
|
| 1029 | - for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) { |
|
| 1030 | - // calculing the next point |
|
| 1031 | - $t1 = ($i * $dt) + $angleBegin; |
|
| 1032 | - $a1 = $x0 + ($rx * cos($t1)); |
|
| 1033 | - $b1 = $y0 + ($ry * sin($t1)); |
|
| 1034 | - $c1 = -$rx * sin($t1); |
|
| 1035 | - $d1 = $ry * cos($t1); |
|
| 1036 | - |
|
| 1037 | - // make the bezier curv |
|
| 1038 | - $this->_Curve( |
|
| 1039 | - $a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm), |
|
| 1040 | - $a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm), |
|
| 1041 | - $a1, $b1, |
|
| 1042 | - $trans |
|
| 1043 | - ); |
|
| 1044 | - |
|
| 1045 | - // save the point |
|
| 1046 | - $a0 = $a1; |
|
| 1047 | - $b0 = $b1; |
|
| 1048 | - $c0 = $c1; |
|
| 1049 | - $d0 = $d1; |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * SVG - make a arc from Pt1 to Pt2, with Radius |
|
| 1055 | - * |
|
| 1056 | - * @param float $x1 |
|
| 1057 | - * @param float $y1 |
|
| 1058 | - * @param float $x2 |
|
| 1059 | - * @param float $y2 |
|
| 1060 | - * @param float $rx |
|
| 1061 | - * @param float $ry |
|
| 1062 | - * @param float $angle deviation angle of the axis X |
|
| 1063 | - * @param integer $l large-arc-flag |
|
| 1064 | - * @param integer $s sweep-flag |
|
| 1065 | - * @param boolean $trans apply transformation |
|
| 1066 | - * @access protected |
|
| 1067 | - */ |
|
| 1068 | - protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s = 0, $trans = false) |
|
| 1069 | - { |
|
| 1070 | - // array to stock the parameters |
|
| 1071 | - $v = array(); |
|
| 1072 | - |
|
| 1073 | - // the original values |
|
| 1074 | - $v['x1'] = $x1; |
|
| 1075 | - $v['y1'] = $y1; |
|
| 1076 | - $v['x2'] = $x2; |
|
| 1077 | - $v['y2'] = $y2; |
|
| 1078 | - $v['rx'] = $rx; |
|
| 1079 | - $v['ry'] = $ry; |
|
| 1080 | - |
|
| 1081 | - // rotate with the deviation angle of the axis X |
|
| 1082 | - $v['xr1'] = $v['x1'] * cos($angle) - $v['y1'] * sin($angle); |
|
| 1083 | - $v['yr1'] = $v['x1'] * sin($angle) + $v['y1'] * cos($angle); |
|
| 1084 | - $v['xr2'] = $v['x2'] * cos($angle) - $v['y2'] * sin($angle); |
|
| 1085 | - $v['yr2'] = $v['x2'] * sin($angle) + $v['y2'] * cos($angle); |
|
| 1086 | - |
|
| 1087 | - // the normalized vector |
|
| 1088 | - $v['Xr1'] = $v['xr1'] / $v['rx']; |
|
| 1089 | - $v['Yr1'] = $v['yr1'] / $v['ry']; |
|
| 1090 | - $v['Xr2'] = $v['xr2'] / $v['rx']; |
|
| 1091 | - $v['Yr2'] = $v['yr2'] / $v['ry']; |
|
| 1092 | - $v['dXr'] = $v['Xr2'] - $v['Xr1']; |
|
| 1093 | - $v['dYr'] = $v['Yr2'] - $v['Yr1']; |
|
| 1094 | - $v['D'] = $v['dXr'] * $v['dXr'] + $v['dYr'] * $v['dYr']; |
|
| 1095 | - |
|
| 1096 | - // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line |
|
| 1097 | - if ($v['D'] == 0 || $v['D'] > 4) { |
|
| 1098 | - $this->_Line($x2, $y2, $trans); |
|
| 1099 | - return false; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd |
|
| 1103 | - $v['s1'] = array(); |
|
| 1104 | - $v['s1']['t'] = sqrt((4. - $v['D']) / $v['D']); |
|
| 1105 | - $v['s1']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s1']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.; |
|
| 1106 | - $v['s1']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s1']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.; |
|
| 1107 | - $v['s1']['xr'] = $v['s1']['Xr'] * $v['rx']; |
|
| 1108 | - $v['s1']['yr'] = $v['s1']['Yr'] * $v['ry']; |
|
| 1109 | - $v['s1']['x'] = $v['s1']['xr'] * cos($angle) + $v['s1']['yr'] * sin($angle); |
|
| 1110 | - $v['s1']['y'] = -$v['s1']['xr'] * sin($angle) + $v['s1']['yr'] * cos($angle); |
|
| 1111 | - $v['s1']['a1'] = atan2($v['y1'] - $v['s1']['y'], $v['x1'] - $v['s1']['x']); |
|
| 1112 | - $v['s1']['a2'] = atan2($v['y2'] - $v['s1']['y'], $v['x2'] - $v['s1']['x']); |
|
| 1113 | - if ($v['s1']['a1'] > $v['s1']['a2']) $v['s1']['a1'] -= 2 * M_PI; |
|
| 1114 | - |
|
| 1115 | - $v['s2'] = array(); |
|
| 1116 | - $v['s2']['t'] = -$v['s1']['t']; |
|
| 1117 | - $v['s2']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s2']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.; |
|
| 1118 | - $v['s2']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s2']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.; |
|
| 1119 | - $v['s2']['xr'] = $v['s2']['Xr'] * $v['rx']; |
|
| 1120 | - $v['s2']['yr'] = $v['s2']['Yr'] * $v['ry']; |
|
| 1121 | - $v['s2']['x'] = $v['s2']['xr'] * cos($angle) + $v['s2']['yr'] * sin($angle); |
|
| 1122 | - $v['s2']['y'] = -$v['s2']['xr'] * sin($angle) + $v['s2']['yr'] * cos($angle); |
|
| 1123 | - $v['s2']['a1'] = atan2($v['y1'] - $v['s2']['y'], $v['x1'] - $v['s2']['x']); |
|
| 1124 | - $v['s2']['a2'] = atan2($v['y2'] - $v['s2']['y'], $v['x2'] - $v['s2']['x']); |
|
| 1125 | - if ($v['s2']['a1'] > $v['s2']['a2']) $v['s2']['a1'] -= 2 * M_PI; |
|
| 1126 | - |
|
| 1127 | - if ( ! $l) { |
|
| 1128 | - if ($s) { |
|
| 1129 | - $xc = $v['s2']['x']; |
|
| 1130 | - $yc = $v['s2']['y']; |
|
| 1131 | - $a1 = $v['s2']['a1']; |
|
| 1132 | - $a2 = $v['s2']['a2']; |
|
| 1133 | - $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans); |
|
| 1134 | - } else { |
|
| 1135 | - $xc = $v['s1']['x']; |
|
| 1136 | - $yc = $v['s1']['y']; |
|
| 1137 | - $a1 = $v['s1']['a1']; |
|
| 1138 | - $a2 = $v['s1']['a2']; |
|
| 1139 | - $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans); |
|
| 1140 | - } |
|
| 1141 | - } else { |
|
| 1142 | - if ($s) { |
|
| 1143 | - $xc = $v['s1']['x']; |
|
| 1144 | - $yc = $v['s1']['y']; |
|
| 1145 | - $a1 = $v['s1']['a1']; |
|
| 1146 | - $a2 = $v['s1']['a2']; |
|
| 1147 | - $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans); |
|
| 1148 | - } else { |
|
| 1149 | - $xc = $v['s2']['x']; |
|
| 1150 | - $yc = $v['s2']['y']; |
|
| 1151 | - $a1 = $v['s2']['a1']; |
|
| 1152 | - $a2 = $v['s2']['a2']; |
|
| 1153 | - $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * SVG - transform the point (reference) |
|
| 1160 | - * |
|
| 1161 | - * @param float &$x |
|
| 1162 | - * @param float &$y |
|
| 1163 | - * @param boolean $trans true => convert into PDF unit |
|
| 1164 | - * @param double $x |
|
| 1165 | - * @param double $y |
|
| 1166 | - * @return boolean |
|
| 1167 | - * @access public |
|
| 1168 | - */ |
|
| 1169 | - public function ptTransform(&$x, &$y, $trans = true) |
|
| 1170 | - { |
|
| 1171 | - // load the last Transfomation Matrix |
|
| 1172 | - $nb = count($this->_transf); |
|
| 1173 | - if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1174 | - else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1175 | - |
|
| 1176 | - // apply the Transformation Matrix |
|
| 1177 | - list($x, $y) = array(($x * $m[0] + $y * $m[2] + $m[4]), ($x * $m[1] + $y * $m[3] + $m[5])); |
|
| 1178 | - |
|
| 1179 | - // if true => convert into PDF unit |
|
| 1180 | - if ($trans) { |
|
| 1181 | - $x = $x * $this->k; |
|
| 1182 | - $y = ($this->h - $y) * $this->k; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - return true; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - /** |
|
| 1189 | - * SVG - add a transformation Matric |
|
| 1190 | - * |
|
| 1191 | - * @param array $n matrix |
|
| 1192 | - * @access public |
|
| 1193 | - */ |
|
| 1194 | - public function doTransform($n = null) |
|
| 1195 | - { |
|
| 1196 | - // get the last Transformation Matrix |
|
| 1197 | - $nb = count($this->_transf); |
|
| 1198 | - if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1199 | - else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1200 | - |
|
| 1201 | - // if no transform, get the Identity Matrix |
|
| 1202 | - if ( ! $n) $n = array(1, 0, 0, 1, 0, 0); |
|
| 1203 | - |
|
| 1204 | - // create the new Transformation Matrix |
|
| 1205 | - $this->_transf[] = array( |
|
| 1206 | - $m[0] * $n[0] + $m[2] * $n[1], |
|
| 1207 | - $m[1] * $n[0] + $m[3] * $n[1], |
|
| 1208 | - $m[0] * $n[2] + $m[2] * $n[3], |
|
| 1209 | - $m[1] * $n[2] + $m[3] * $n[3], |
|
| 1210 | - $m[0] * $n[4] + $m[2] * $n[5] + $m[4], |
|
| 1211 | - $m[1] * $n[4] + $m[3] * $n[5] + $m[5] |
|
| 1212 | - ); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * SVG - remove a transformation Matric |
|
| 1217 | - * |
|
| 1218 | - * @access public |
|
| 1219 | - */ |
|
| 1220 | - public function undoTransform() |
|
| 1221 | - { |
|
| 1222 | - array_pop($this->_transf); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * Convert a HTML2PDF barcode in a TCPDF barcode |
|
| 1227 | - * |
|
| 1228 | - * @param string $code code to print |
|
| 1229 | - * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats) |
|
| 1230 | - * @param int $x x position in user units |
|
| 1231 | - * @param int $y y position in user units |
|
| 1232 | - * @param int $w width in user units |
|
| 1233 | - * @param int $h height in user units |
|
| 1234 | - * @param int $labelFontsize of the Test Label. If false : no Label |
|
| 1235 | - * @param array $color color of the foreground |
|
| 1236 | - * @access public |
|
| 1237 | - */ |
|
| 1238 | - public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color) |
|
| 1239 | - { |
|
| 1240 | - // the style of the barcode |
|
| 1241 | - $style = array( |
|
| 1242 | - 'position' => 'S', |
|
| 1243 | - 'text' => ($labelFontsize ? true : false), |
|
| 1244 | - 'fgcolor' => $color, |
|
| 1245 | - 'bgcolor' => false, |
|
| 1246 | - ); |
|
| 1247 | - |
|
| 1248 | - // build the barcode |
|
| 1249 | - $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N'); |
|
| 1250 | - |
|
| 1251 | - // it Label => add the FontSize to the height |
|
| 1252 | - if ($labelFontsize) $h += ($labelFontsize); |
|
| 1253 | - |
|
| 1254 | - // return the size of the barcode |
|
| 1255 | - return array($w, $h); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * create a automatic Index on a page |
|
| 1260 | - * |
|
| 1261 | - * @param html2pdf $obj parent object |
|
| 1262 | - * @param string $titre Title of the Index Page |
|
| 1263 | - * @param integer $sizeTitle Font size for hthe Title |
|
| 1264 | - * @param integer $sizeBookmark Font size for the bookmarks |
|
| 1265 | - * @param boolean $bookmarkTitle Bookmark the Title |
|
| 1266 | - * @param boolean $displayPage Display the page number for each bookmark |
|
| 1267 | - * @param integer $page draw the automatic Index on a specific Page. if null => add a page at the end |
|
| 1268 | - * @param string $fontName FontName to use |
|
| 1269 | - * @access public |
|
| 1270 | - */ |
|
| 1271 | - public function createIndex( |
|
| 1272 | - &$obj, |
|
| 1273 | - $titre = 'Index', |
|
| 1274 | - $sizeTitle = 20, |
|
| 1275 | - $sizeBookmark = 15, |
|
| 1276 | - $bookmarkTitle = true, |
|
| 1277 | - $displayPage = true, |
|
| 1278 | - $page = null, |
|
| 1279 | - $fontName = 'helvetica') |
|
| 1280 | - { |
|
| 1281 | - // bookmark the Title if wanted |
|
| 1282 | - if ($bookmarkTitle) { |
|
| 1283 | - $this->Bookmark($titre, 0, -1); |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - // display the Title with the good Font size |
|
| 1287 | - $this->SetFont($fontName, '', $sizeTitle); |
|
| 1288 | - $this->Cell(0, 5, $titre, 0, 1, 'C'); |
|
| 1289 | - |
|
| 1290 | - // set the good Font size for the bookmarks |
|
| 1291 | - $this->SetFont($fontName, '', $sizeBookmark); |
|
| 1292 | - $this->Ln(10); |
|
| 1293 | - |
|
| 1294 | - // get the number of bookmarks |
|
| 1295 | - $size = sizeof($this->outlines); |
|
| 1296 | - |
|
| 1297 | - // get the size of the "P. xx" cell |
|
| 1298 | - $pageCellSize = $this->GetStringWidth('p. '.$this->outlines[$size - 1]['p']) + 2; |
|
| 1299 | - |
|
| 1300 | - // Foreach bookmark |
|
| 1301 | - for ($i = 0; $i < $size; $i++) { |
|
| 1302 | - // if we need a new page => add a new page |
|
| 1303 | - if ($this->getY() + $this->FontSize >= ($this->h - $this->bMargin)) { |
|
| 1304 | - $obj->_INDEX_NewPage($page); |
|
| 1305 | - $this->SetFont($fontName, '', $sizeBookmark); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - // Offset of the current level |
|
| 1309 | - $level = $this->outlines[$i]['l']; |
|
| 1310 | - if ($level > 0) $this->Cell($level * 8); |
|
| 1311 | - |
|
| 1312 | - // Caption (cut to fit on the width page) |
|
| 1313 | - $str = $this->outlines[$i]['t']; |
|
| 1314 | - $strsize = $this->GetStringWidth($str); |
|
| 1315 | - $availableSize = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - 4; |
|
| 1316 | - while ($strsize >= $availableSize) { |
|
| 1317 | - $str = substr($str, 0, -1); |
|
| 1318 | - $strsize = $this->GetStringWidth($str); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - // if we want to display the page nmber |
|
| 1322 | - if ($displayPage) { |
|
| 1323 | - // display the Bookmark Caption |
|
| 1324 | - $this->Cell($strsize + 2, $this->FontSize + 2, $str); |
|
| 1325 | - |
|
| 1326 | - //Filling dots |
|
| 1327 | - $w = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - ($strsize + 2); |
|
| 1328 | - $nb = $w / $this->GetStringWidth('.'); |
|
| 1329 | - $dots = str_repeat('.', $nb); |
|
| 1330 | - $this->Cell($w, $this->FontSize + 2, $dots, 0, 0, 'R'); |
|
| 1331 | - |
|
| 1332 | - //Page number |
|
| 1333 | - $this->Cell($pageCellSize, $this->FontSize + 2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R'); |
|
| 1334 | - } else { |
|
| 1335 | - // display the Bookmark Caption |
|
| 1336 | - $this->Cell($strsize + 2, $this->FontSize + 2, $str, 0, 1); |
|
| 1337 | - } |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Returns the string alias used for the total number of pages. |
|
| 1343 | - * |
|
| 1344 | - * @access public |
|
| 1345 | - * @return string; |
|
| 1346 | - * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias() |
|
| 1347 | - */ |
|
| 1348 | - public function getMyAliasNbPages() |
|
| 1349 | - { |
|
| 1350 | - if ($this->_myLastPageGroupNb == 0) { |
|
| 1351 | - return $this->getAliasNbPages(); |
|
| 1352 | - } else { |
|
| 1353 | - $old = $this->currpagegroup; |
|
| 1354 | - $this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}'; |
|
| 1355 | - $new = $this->getPageGroupAlias(); |
|
| 1356 | - $this->currpagegroup = $old; |
|
| 1357 | - |
|
| 1358 | - return $new; |
|
| 1359 | - } |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Returns the current page number. |
|
| 1364 | - * |
|
| 1365 | - * @access public |
|
| 1366 | - * @param integer $page |
|
| 1367 | - * @return integer; |
|
| 1368 | - */ |
|
| 1369 | - public function getMyNumPage($page = null) |
|
| 1370 | - { |
|
| 1371 | - if ($page === null) { |
|
| 1372 | - $page = $this->page; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - if ($this->_myLastPageGroupNb == 0) { |
|
| 1376 | - return $page; |
|
| 1377 | - } else { |
|
| 1378 | - return $page - $this->_myLastPageGroup; |
|
| 1379 | - } |
|
| 1380 | - } |
|
| 1381 | - |
|
| 1382 | - /** |
|
| 1383 | - * Start a new group of pages |
|
| 1384 | - * |
|
| 1385 | - * @access public |
|
| 1386 | - * @return integer; |
|
| 1387 | - * @see tcpdf::startPageGroup |
|
| 1388 | - */ |
|
| 1389 | - public function myStartPageGroup() |
|
| 1390 | - { |
|
| 1391 | - $this->_myLastPageGroup = $this->page - 1; |
|
| 1392 | - $this->_myLastPageGroupNb++; |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * get $_myLastPageGroup; |
|
| 1397 | - * |
|
| 1398 | - * @access public |
|
| 1399 | - * @return integer $_myLastPageGroup; |
|
| 1400 | - */ |
|
| 1401 | - public function getMyLastPageGroup() |
|
| 1402 | - { |
|
| 1403 | - return $this->_myLastPageGroup; |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * set $_myLastPageGroup; |
|
| 1408 | - * |
|
| 1409 | - * @access public |
|
| 1410 | - * @param integer $myLastPageGroup; |
|
| 1411 | - * @param integer $myLastPageGroup |
|
| 1412 | - */ |
|
| 1413 | - public function setMyLastPageGroup($myLastPageGroup) |
|
| 1414 | - { |
|
| 1415 | - $this->_myLastPageGroup = $myLastPageGroup; |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * get $_myLastPageGroupNb; |
|
| 1420 | - * |
|
| 1421 | - * @access public |
|
| 1422 | - * @return integer $_myLastPageGroupNb; |
|
| 1423 | - */ |
|
| 1424 | - public function getMyLastPageGroupNb() |
|
| 1425 | - { |
|
| 1426 | - return $this->_myLastPageGroupNb; |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * set $_myLastPageGroupNb; |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param integer $myLastPageGroupNb; |
|
| 1434 | - * @param integer $myLastPageGroupNb |
|
| 1435 | - */ |
|
| 1436 | - public function setMyLastPageGroupNb($myLastPageGroupNb) |
|
| 1437 | - { |
|
| 1438 | - $this->_myLastPageGroupNb = $myLastPageGroupNb; |
|
| 1439 | - } |
|
| 17 | + protected $_footerParam = array(); |
|
| 18 | + protected $_transf = array(); |
|
| 19 | + protected $_myLastPageGroup = null; |
|
| 20 | + protected $_myLastPageGroupNb = 0; |
|
| 21 | + |
|
| 22 | + // used to make a radius with bezier : (4/3 * (sqrt(2) - 1)) |
|
| 23 | + const MY_ARC = 0.5522847498; |
|
| 24 | + |
|
| 25 | + // nb of segment to build a arc with bezier curv |
|
| 26 | + const ARC_NB_SEGMENT = 8; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * class constructor |
|
| 30 | + * |
|
| 31 | + * @param string $orientation page orientation, same as TCPDF |
|
| 32 | + * @param string $unit User measure unit, same as TCPDF |
|
| 33 | + * @param mixed $format The format used for pages, same as TCPDF |
|
| 34 | + * @param boolean $unicode TRUE means that the input text is unicode (default = true) |
|
| 35 | + * @param String $encoding charset encoding; default is UTF-8 |
|
| 36 | + * @param boolean $diskcache if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower). |
|
| 37 | + * @access public |
|
| 38 | + */ |
|
| 39 | + public function __construct( |
|
| 40 | + $orientation = 'P', |
|
| 41 | + $unit = 'mm', |
|
| 42 | + $format = 'A4', |
|
| 43 | + $unicode = true, |
|
| 44 | + $encoding = 'UTF-8', |
|
| 45 | + $diskcache = false) |
|
| 46 | + { |
|
| 47 | + // call the parent constructor |
|
| 48 | + parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache); |
|
| 49 | + |
|
| 50 | + // init the specific parameters used by HTML2PDF |
|
| 51 | + $this->SetCreator(PDF_CREATOR); |
|
| 52 | + $this->SetAutoPageBreak(false, 0); |
|
| 53 | + $this->linestyleCap = '2 J'; |
|
| 54 | + $this->setPrintHeader(false); |
|
| 55 | + $this->jpeg_quality = 90; |
|
| 56 | + |
|
| 57 | + // prepare the automatic footer |
|
| 58 | + $this->SetMyFooter(); |
|
| 59 | + |
|
| 60 | + $this->cMargin = 0; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Set the parameters for the automatic footer |
|
| 65 | + * |
|
| 66 | + * @param boolean $page display the page number |
|
| 67 | + * @param boolean $date display the date |
|
| 68 | + * @param boolean $hour display the hour |
|
| 69 | + * @param boolean $form display a warning abour forms |
|
| 70 | + * @access public |
|
| 71 | + */ |
|
| 72 | + public function SetMyFooter($page = false, $date = false, $hour = false, $form = false) |
|
| 73 | + { |
|
| 74 | + $page = ($page ? true : false); |
|
| 75 | + $date = ($date ? true : false); |
|
| 76 | + $hour = ($hour ? true : false); |
|
| 77 | + $form = ($form ? true : false); |
|
| 78 | + |
|
| 79 | + $this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * This function is call automatically by TCPDF at the end of a page |
|
| 84 | + * It takes no parameters |
|
| 85 | + * |
|
| 86 | + * @access public |
|
| 87 | + */ |
|
| 88 | + public function Footer() |
|
| 89 | + { |
|
| 90 | + // prepare the text from the tranlated text |
|
| 91 | + $txt = ''; |
|
| 92 | + if ($this->_footerParam['form']) { |
|
| 93 | + $txt = (HTML2PDF_locale::get('pdf05')); |
|
| 94 | + } |
|
| 95 | + if ($this->_footerParam['date'] && $this->_footerParam['hour']) { |
|
| 96 | + $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03')); |
|
| 97 | + } |
|
| 98 | + if ($this->_footerParam['date'] && ! $this->_footerParam['hour']) { |
|
| 99 | + $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01')); |
|
| 100 | + } |
|
| 101 | + if ( ! $this->_footerParam['date'] && $this->_footerParam['hour']) { |
|
| 102 | + $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02')); |
|
| 103 | + } |
|
| 104 | + if ($this->_footerParam['page']) { |
|
| 105 | + $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04')); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if (strlen($txt) > 0) { |
|
| 109 | + // replace some values |
|
| 110 | + $toReplace = array( |
|
| 111 | + '[[date_d]]' => date('d'), |
|
| 112 | + '[[date_m]]' => date('m'), |
|
| 113 | + '[[date_y]]' => date('Y'), |
|
| 114 | + '[[date_h]]' => date('H'), |
|
| 115 | + '[[date_i]]' => date('i'), |
|
| 116 | + '[[date_s]]' => date('s'), |
|
| 117 | + '[[page_cu]]' => $this->getMyNumPage(), |
|
| 118 | + '[[page_nb]]' => $this->getMyAliasNbPages(), |
|
| 119 | + ); |
|
| 120 | + $txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt); |
|
| 121 | + |
|
| 122 | + // draw the footer |
|
| 123 | + parent::SetY(-11); |
|
| 124 | + $this->SetFont('helvetica', 'I', 8); |
|
| 125 | + $this->Cell(0, 10, $txt, 0, 0, 'R'); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * after cloning a object, we does not want to clone all the front informations |
|
| 131 | + * because it take a lot a time and a lot of memory => we use reference |
|
| 132 | + * |
|
| 133 | + * @param &HTML2PDF_myPdf object |
|
| 134 | + * @param HTML2PDF_myPdf $pdf |
|
| 135 | + * @access public |
|
| 136 | + */ |
|
| 137 | + public function cloneFontFrom(&$pdf) |
|
| 138 | + { |
|
| 139 | + $this->fonts = &$pdf->getFonts(); |
|
| 140 | + $this->FontFiles = &$pdf->getFontFiles(); |
|
| 141 | + $this->diffs = &$pdf->getDiffs(); |
|
| 142 | + $this->fontlist = &$pdf->getFontList(); |
|
| 143 | + $this->numfonts = &$pdf->getNumFonts(); |
|
| 144 | + $this->fontkeys = &$pdf->getFontKeys(); |
|
| 145 | + $this->font_obj_ids = &$pdf->getFontObjIds(); |
|
| 146 | + $this->annotation_fonts = &$pdf->getAnnotFonts(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * multiple public accessor for some private attributs |
|
| 151 | + * used only by cloneFontFrom |
|
| 152 | + * |
|
| 153 | + * @return &array |
|
| 154 | + * @access public |
|
| 155 | + */ |
|
| 156 | + public function &getFonts() |
|
| 157 | + { |
|
| 158 | + return $this->fonts; |
|
| 159 | + } |
|
| 160 | + public function &getFontFiles() |
|
| 161 | + { |
|
| 162 | + return $this->FontFiles; |
|
| 163 | + } |
|
| 164 | + public function &getDiffs() |
|
| 165 | + { |
|
| 166 | + return $this->diffs; |
|
| 167 | + } |
|
| 168 | + public function &getFontList() |
|
| 169 | + { |
|
| 170 | + return $this->fontlist; |
|
| 171 | + } |
|
| 172 | + public function &getNumFonts() |
|
| 173 | + { |
|
| 174 | + return $this->numfonts; |
|
| 175 | + } |
|
| 176 | + public function &getFontKeys() |
|
| 177 | + { |
|
| 178 | + return $this->fontkeys; |
|
| 179 | + } |
|
| 180 | + public function &getFontObjIds() |
|
| 181 | + { |
|
| 182 | + return $this->font_obj_ids; |
|
| 183 | + } |
|
| 184 | + public function &getAnnotFonts() |
|
| 185 | + { |
|
| 186 | + return $this->annotation_fonts; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Verify that a Font is already loaded |
|
| 191 | + * |
|
| 192 | + * @param string Font Key |
|
| 193 | + * @return boolean |
|
| 194 | + * @access public |
|
| 195 | + */ |
|
| 196 | + public function isLoadedFont($fontKey) |
|
| 197 | + { |
|
| 198 | + if (isset($this->fonts[$fontKey])) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if (isset($this->CoreFonts[$fontKey])) { |
|
| 203 | + return true; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Get the Word Spacing |
|
| 211 | + * |
|
| 212 | + * @access public |
|
| 213 | + * @return float word spacing |
|
| 214 | + */ |
|
| 215 | + public function getWordSpacing() |
|
| 216 | + { |
|
| 217 | + return $this->ws; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * set the Word Spacing |
|
| 222 | + * |
|
| 223 | + * @param float word spacing |
|
| 224 | + * @access public |
|
| 225 | + */ |
|
| 226 | + public function setWordSpacing($ws = 0.) |
|
| 227 | + { |
|
| 228 | + $this->ws = $ws; |
|
| 229 | + $this->_out(sprintf('%.3F Tw', $ws * $this->k)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * start to use a rectangular Cliping Path with radius corners |
|
| 234 | + * |
|
| 235 | + * @param float $x (top left corner) |
|
| 236 | + * @param float $y (top left corner) |
|
| 237 | + * @param float $w (x+w = botom rigth corner) |
|
| 238 | + * @param float $h (y+h = botom rigth corner) |
|
| 239 | + * @param array $cornerTL radius of the Top Left corner |
|
| 240 | + * @param array $cornerTR radius of the Top Right corner |
|
| 241 | + * @param array $cornerBL radius of the Bottom Left corner |
|
| 242 | + * @param array $cornerBR radius of the Bottom Right corner |
|
| 243 | + * @access public |
|
| 244 | + */ |
|
| 245 | + public function clippingPathStart( |
|
| 246 | + $x = null, |
|
| 247 | + $y = null, |
|
| 248 | + $w = null, |
|
| 249 | + $h = null, |
|
| 250 | + $cornerTL = null, |
|
| 251 | + $cornerTR = null, |
|
| 252 | + $cornerBL = null, |
|
| 253 | + $cornerBR = null) |
|
| 254 | + { |
|
| 255 | + // init the path |
|
| 256 | + $path = ''; |
|
| 257 | + |
|
| 258 | + // if we have the position and the size of the rectangle, we can proceed |
|
| 259 | + if ($x !== null && $y !== null && $w !== null && $h !== null) { |
|
| 260 | + // the positions of the rectangle's corners |
|
| 261 | + $x1 = $x * $this->k; |
|
| 262 | + $y1 = ($this->h - $y) * $this->k; |
|
| 263 | + |
|
| 264 | + $x2 = ($x + $w) * $this->k; |
|
| 265 | + $y2 = ($this->h - $y) * $this->k; |
|
| 266 | + |
|
| 267 | + $x3 = ($x + $w) * $this->k; |
|
| 268 | + $y3 = ($this->h - $y - $h) * $this->k; |
|
| 269 | + |
|
| 270 | + $x4 = $x * $this->k; |
|
| 271 | + $y4 = ($this->h - $y - $h) * $this->k; |
|
| 272 | + |
|
| 273 | + // if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle |
|
| 274 | + if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) { |
|
| 275 | + // prepare the radius values |
|
| 276 | + if ($cornerTL) { |
|
| 277 | + $cornerTL[0] = $cornerTL[0] * $this->k; |
|
| 278 | + $cornerTL[1] = -$cornerTL[1] * $this->k; |
|
| 279 | + } |
|
| 280 | + if ($cornerTR) { |
|
| 281 | + $cornerTR[0] = $cornerTR[0] * $this->k; |
|
| 282 | + $cornerTR[1] = -$cornerTR[1] * $this->k; |
|
| 283 | + } |
|
| 284 | + if ($cornerBL) { |
|
| 285 | + $cornerBL[0] = $cornerBL[0] * $this->k; |
|
| 286 | + $cornerBL[1] = -$cornerBL[1] * $this->k; |
|
| 287 | + } |
|
| 288 | + if ($cornerBR) { |
|
| 289 | + $cornerBR[0] = $cornerBR[0] * $this->k; |
|
| 290 | + $cornerBR[1] = -$cornerBR[1] * $this->k; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // if TL radius then specific start else (X1,Y1) |
|
| 294 | + if ($cornerTL) { |
|
| 295 | + $path .= sprintf('%.2F %.2F m ', $x1 + $cornerTL[0], $y1); |
|
| 296 | + } else { |
|
| 297 | + $path .= sprintf('%.2F %.2F m ', $x1, $y1); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // if TR radius then line + arc, else line to (X2,Y2) |
|
| 301 | + if ($cornerTR) { |
|
| 302 | + $xt1 = ($x2 - $cornerTR[0]) + $cornerTR[0] * self::MY_ARC; |
|
| 303 | + $yt1 = ($y2 + $cornerTR[1]) - $cornerTR[1]; |
|
| 304 | + $xt2 = ($x2 - $cornerTR[0]) + $cornerTR[0]; |
|
| 305 | + $yt2 = ($y2 + $cornerTR[1]) - $cornerTR[1] * self::MY_ARC; |
|
| 306 | + |
|
| 307 | + $path .= sprintf('%.2F %.2F l ', $x2 - $cornerTR[0], $y2); |
|
| 308 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2 + $cornerTR[1]); |
|
| 309 | + } else { |
|
| 310 | + $path .= sprintf('%.2F %.2F l ', $x2, $y2); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + // if BR radius then line + arc, else line to (X3, Y3) |
|
| 314 | + if ($cornerBR) { |
|
| 315 | + $xt1 = ($x3 - $cornerBR[0]) + $cornerBR[0]; |
|
| 316 | + $yt1 = ($y3 - $cornerBR[1]) + $cornerBR[1] * self::MY_ARC; |
|
| 317 | + $xt2 = ($x3 - $cornerBR[0]) + $cornerBR[0] * self::MY_ARC; |
|
| 318 | + $yt2 = ($y3 - $cornerBR[1]) + $cornerBR[1]; |
|
| 319 | + |
|
| 320 | + $path .= sprintf('%.2F %.2F l ', $x3, $y3 - $cornerBR[1]); |
|
| 321 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3 - $cornerBR[0], $y3); |
|
| 322 | + } else { |
|
| 323 | + $path .= sprintf('%.2F %.2F l ', $x3, $y3); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // if BL radius then line + arc, else line to (X4, Y4) |
|
| 327 | + if ($cornerBL) { |
|
| 328 | + $xt1 = ($x4 + $cornerBL[0]) - $cornerBL[0] * self::MY_ARC; |
|
| 329 | + $yt1 = ($y4 - $cornerBL[1]) + $cornerBL[1]; |
|
| 330 | + $xt2 = ($x4 + $cornerBL[0]) - $cornerBL[0]; |
|
| 331 | + $yt2 = ($y4 - $cornerBL[1]) + $cornerBL[1] * self::MY_ARC; |
|
| 332 | + |
|
| 333 | + $path .= sprintf('%.2F %.2F l ', $x4 + $cornerBL[0], $y4); |
|
| 334 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4 - $cornerBL[1]); |
|
| 335 | + } else { |
|
| 336 | + $path .= sprintf('%.2F %.2F l ', $x4, $y4); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // if RL radius then line + arc |
|
| 340 | + if ($cornerTL) { |
|
| 341 | + $xt1 = ($x1 + $cornerTL[0]) - $cornerTL[0]; |
|
| 342 | + $yt1 = ($y1 + $cornerTL[1]) - $cornerTL[1] * self::MY_ARC; |
|
| 343 | + $xt2 = ($x1 + $cornerTL[0]) - $cornerTL[0] * self::MY_ARC; |
|
| 344 | + $yt2 = ($y1 + $cornerTL[1]) - $cornerTL[1]; |
|
| 345 | + |
|
| 346 | + $path .= sprintf('%.2F %.2F l ', $x1, $y1 + $cornerTL[1]); |
|
| 347 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1 + $cornerTL[0], $y1); |
|
| 348 | + } |
|
| 349 | + } else { |
|
| 350 | + $path .= sprintf('%.2F %.2F m ', $x1, $y1); |
|
| 351 | + $path .= sprintf('%.2F %.2F l ', $x2, $y2); |
|
| 352 | + $path .= sprintf('%.2F %.2F l ', $x3, $y3); |
|
| 353 | + $path .= sprintf('%.2F %.2F l ', $x4, $y4); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // close the path |
|
| 357 | + $path .= ' h W n'; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // using the path as a clipping path |
|
| 361 | + $this->_out('q '.$path.' '); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * stop to use the Cliping Path |
|
| 366 | + * |
|
| 367 | + * @access public |
|
| 368 | + */ |
|
| 369 | + public function clippingPathStop() |
|
| 370 | + { |
|
| 371 | + $this->_out(' Q'); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * draw a filled corner of a border with a external and a internal radius |
|
| 376 | + * /--------+ ext2 |
|
| 377 | + * / | |
|
| 378 | + * / /-------+ int2 |
|
| 379 | + * / / |
|
| 380 | + * | / |
|
| 381 | + * | | |
|
| 382 | + * | | |
|
| 383 | + * ext1 +-+ int1 + cen |
|
| 384 | + * |
|
| 385 | + * @param float $ext1X |
|
| 386 | + * @param float $ext1Y |
|
| 387 | + * @param float $ext2X |
|
| 388 | + * @param float $ext2Y |
|
| 389 | + * @param float $int1X |
|
| 390 | + * @param float $int1Y |
|
| 391 | + * @param float $int2X |
|
| 392 | + * @param float $int2Y |
|
| 393 | + * @param float $cenX |
|
| 394 | + * @param float $cenY |
|
| 395 | + * @access public |
|
| 396 | + */ |
|
| 397 | + public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY) |
|
| 398 | + { |
|
| 399 | + // prepare the coordinates |
|
| 400 | + $ext1X = $ext1X * $this->k; |
|
| 401 | + $ext2X = $ext2X * $this->k; |
|
| 402 | + $int1X = $int1X * $this->k; |
|
| 403 | + $int2X = $int2X * $this->k; |
|
| 404 | + $cenX = $cenX * $this->k; |
|
| 405 | + |
|
| 406 | + $ext1Y = ($this->h - $ext1Y) * $this->k; |
|
| 407 | + $ext2Y = ($this->h - $ext2Y) * $this->k; |
|
| 408 | + $int1Y = ($this->h - $int1Y) * $this->k; |
|
| 409 | + $int2Y = ($this->h - $int2Y) * $this->k; |
|
| 410 | + $cenY = ($this->h - $cenY) * $this->k; |
|
| 411 | + |
|
| 412 | + // init the curve |
|
| 413 | + $path = ''; |
|
| 414 | + |
|
| 415 | + if ($ext1X - $cenX != 0) { |
|
| 416 | + $xt1 = $cenX + ($ext1X - $cenX); |
|
| 417 | + $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC; |
|
| 418 | + $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC; |
|
| 419 | + $yt2 = $cenY + ($ext2Y - $cenY); |
|
| 420 | + } else { |
|
| 421 | + $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC; |
|
| 422 | + $yt1 = $cenY + ($ext1Y - $cenY); |
|
| 423 | + $xt2 = $cenX + ($ext2X - $cenX); |
|
| 424 | + $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC; |
|
| 425 | + } |
|
| 426 | + $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y); |
|
| 427 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y); |
|
| 428 | + |
|
| 429 | + if ($int1X - $cenX != 0) { |
|
| 430 | + $xt1 = $cenX + ($int1X - $cenX) * self::MY_ARC; |
|
| 431 | + $yt1 = $cenY + ($int2Y - $cenY); |
|
| 432 | + $xt2 = $cenX + ($int1X - $cenX); |
|
| 433 | + $yt2 = $cenY + ($int2Y - $cenY) * self::MY_ARC; |
|
| 434 | + } else { |
|
| 435 | + $xt1 = $cenX + ($int2X - $cenX); |
|
| 436 | + $yt1 = $cenY + ($int1Y - $cenY) * self::MY_ARC; |
|
| 437 | + $xt2 = $cenX + ($int2X - $cenX) * self::MY_ARC; |
|
| 438 | + $yt2 = $cenY + ($int1Y - $cenY); |
|
| 439 | + } |
|
| 440 | + $path .= sprintf('%.2F %.2F l ', $int2X, $int2Y); |
|
| 441 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y); |
|
| 442 | + |
|
| 443 | + // draw the curve |
|
| 444 | + $this->_out($path.'f'); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * draw a filled corner of a border with only a external radius |
|
| 449 | + * /--+ ext2 |
|
| 450 | + * / | |
|
| 451 | + * / | |
|
| 452 | + * / | |
|
| 453 | + * | | |
|
| 454 | + * | | |
|
| 455 | + * | | |
|
| 456 | + * ext1 +-----+ int + cen |
|
| 457 | + * |
|
| 458 | + * @param float $ext1X |
|
| 459 | + * @param float $ext1Y |
|
| 460 | + * @param float $ext2X |
|
| 461 | + * @param float $ext2Y |
|
| 462 | + * @param float $intX |
|
| 463 | + * @param float $intY |
|
| 464 | + * @param float $cenX |
|
| 465 | + * @param float $cenY |
|
| 466 | + * @access public |
|
| 467 | + */ |
|
| 468 | + public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY) |
|
| 469 | + { |
|
| 470 | + // prepare the coordinates |
|
| 471 | + $ext1X = $ext1X * $this->k; |
|
| 472 | + $ext2X = $ext2X * $this->k; |
|
| 473 | + $intX = $intX * $this->k; |
|
| 474 | + $cenX = $cenX * $this->k; |
|
| 475 | + |
|
| 476 | + $ext1Y = ($this->h - $ext1Y) * $this->k; |
|
| 477 | + $ext2Y = ($this->h - $ext2Y) * $this->k; |
|
| 478 | + $intY = ($this->h - $intY) * $this->k; |
|
| 479 | + $cenY = ($this->h - $cenY) * $this->k; |
|
| 480 | + |
|
| 481 | + // init the curve |
|
| 482 | + $path = ''; |
|
| 483 | + |
|
| 484 | + if ($ext1X - $cenX != 0) { |
|
| 485 | + $xt1 = $cenX + ($ext1X - $cenX); |
|
| 486 | + $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC; |
|
| 487 | + $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC; |
|
| 488 | + $yt2 = $cenY + ($ext2Y - $cenY); |
|
| 489 | + } else { |
|
| 490 | + $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC; |
|
| 491 | + $yt1 = $cenY + ($ext1Y - $cenY); |
|
| 492 | + $xt2 = $cenX + ($ext2X - $cenX); |
|
| 493 | + $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC; |
|
| 494 | + } |
|
| 495 | + $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y); |
|
| 496 | + $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y); |
|
| 497 | + $path .= sprintf('%.2F %.2F l ', $intX, $intY); |
|
| 498 | + $path .= sprintf('%.2F %.2F l ', $ext1X, $ext1Y); |
|
| 499 | + |
|
| 500 | + // draw the curve |
|
| 501 | + $this->_out($path.'f'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Start a transformation |
|
| 506 | + * |
|
| 507 | + * @access public |
|
| 508 | + */ |
|
| 509 | + public function startTransform() |
|
| 510 | + { |
|
| 511 | + $this->_out('q'); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Stop a transformation |
|
| 516 | + * |
|
| 517 | + * @access public |
|
| 518 | + */ |
|
| 519 | + public function stopTransform() |
|
| 520 | + { |
|
| 521 | + $this->_out('Q'); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * add a Translate transformation |
|
| 526 | + * |
|
| 527 | + * @access public |
|
| 528 | + */ |
|
| 529 | + public function setTranslate($xT, $yT) |
|
| 530 | + { |
|
| 531 | + // Matrix for Translate |
|
| 532 | + $tm[0] = 1; |
|
| 533 | + $tm[1] = 0; |
|
| 534 | + $tm[2] = 0; |
|
| 535 | + $tm[3] = 1; |
|
| 536 | + $tm[4] = $xT * $this->k; |
|
| 537 | + $tm[5] = -$yT * $this->k; |
|
| 538 | + |
|
| 539 | + // apply the Transform Matric |
|
| 540 | + $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * add a Rotate transformation |
|
| 545 | + * |
|
| 546 | + * @param float $angle |
|
| 547 | + * @access public |
|
| 548 | + */ |
|
| 549 | + public function setRotation($angle, $xC = null, $yC = null) |
|
| 550 | + { |
|
| 551 | + // if no center, rotate around the current posiition |
|
| 552 | + if ($xC === null) $xC = $this->x; |
|
| 553 | + if ($yC === null) $yC = $this->y; |
|
| 554 | + |
|
| 555 | + // prepare the coordinate |
|
| 556 | + $yC = ($this->h - $yC) * $this->k; |
|
| 557 | + $xC *= $this->k; |
|
| 558 | + |
|
| 559 | + // Matrix for Rotate |
|
| 560 | + $tm[0] = cos(deg2rad($angle)); |
|
| 561 | + $tm[1] = sin(deg2rad($angle)); |
|
| 562 | + $tm[2] = -$tm[1]; |
|
| 563 | + $tm[3] = $tm[0]; |
|
| 564 | + $tm[4] = $xC + $tm[1] * $yC - $tm[0] * $xC; |
|
| 565 | + $tm[5] = $yC - $tm[0] * $yC - $tm[1] * $xC; |
|
| 566 | + |
|
| 567 | + // apply the Transform Matric |
|
| 568 | + $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5])); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * we redifine the original SetX method, because we don't want the automatic treatment. |
|
| 573 | + * It is HTML2PDF that make the treatment |
|
| 574 | + * |
|
| 575 | + * @param float $x |
|
| 576 | + * @param boolean $rtloff NOT USED |
|
| 577 | + * @access public |
|
| 578 | + */ |
|
| 579 | + public function SetX($x, $rtloff = false) |
|
| 580 | + { |
|
| 581 | + $this->x = $x; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * we redifine the original SetY method, because we don't want the automatic treatment. |
|
| 586 | + * It is HTML2PDF that make the treatment |
|
| 587 | + * |
|
| 588 | + * @param float $y |
|
| 589 | + * @param boolean $resetx Reset the X position |
|
| 590 | + * @param boolean $rtloff NOT USED |
|
| 591 | + * @access public |
|
| 592 | + */ |
|
| 593 | + public function SetY($y, $resetx = true, $rtloff = false) |
|
| 594 | + { |
|
| 595 | + if ($resetx) |
|
| 596 | + $this->x = $this->lMargin; |
|
| 597 | + |
|
| 598 | + $this->y = $y; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * we redifine the original SetXY method, because we don't want the automatic treatment. |
|
| 603 | + * It is HTML2PDF that make the treatment |
|
| 604 | + * |
|
| 605 | + * @param integer $x |
|
| 606 | + * @param integer $y |
|
| 607 | + * @param boolean $rtloff NOT USED |
|
| 608 | + * @access public |
|
| 609 | + */ |
|
| 610 | + public function SetXY($x, $y, $rtloff = false) |
|
| 611 | + { |
|
| 612 | + $this->x = $x; |
|
| 613 | + $this->y = $y; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it |
|
| 618 | + * |
|
| 619 | + * @param mixed |
|
| 620 | + * @return mixed |
|
| 621 | + * @access public |
|
| 622 | + */ |
|
| 623 | + public function getK() |
|
| 624 | + { |
|
| 625 | + return $this->k; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * @return double |
|
| 630 | + */ |
|
| 631 | + public function getW() |
|
| 632 | + { |
|
| 633 | + return $this->w; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * @return double |
|
| 638 | + */ |
|
| 639 | + public function getH() |
|
| 640 | + { |
|
| 641 | + return $this->h; |
|
| 642 | + } |
|
| 643 | + public function getlMargin() |
|
| 644 | + { |
|
| 645 | + return $this->lMargin; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @return double |
|
| 650 | + */ |
|
| 651 | + public function getrMargin() |
|
| 652 | + { |
|
| 653 | + return $this->rMargin; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * @return double |
|
| 658 | + */ |
|
| 659 | + public function gettMargin() |
|
| 660 | + { |
|
| 661 | + return $this->tMargin; |
|
| 662 | + } |
|
| 663 | + public function getbMargin() |
|
| 664 | + { |
|
| 665 | + return $this->bMargin; |
|
| 666 | + } |
|
| 667 | + public function setbMargin($v) |
|
| 668 | + { |
|
| 669 | + $this->bMargin = $v; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * SVG - Convert a SVG Style in PDF Style |
|
| 674 | + * |
|
| 675 | + * @param array $styles SVG Style |
|
| 676 | + * @return string PDF style |
|
| 677 | + * @access public |
|
| 678 | + */ |
|
| 679 | + public function svgSetStyle($styles) |
|
| 680 | + { |
|
| 681 | + // init the PDF style |
|
| 682 | + $style = ''; |
|
| 683 | + |
|
| 684 | + // Style : fill |
|
| 685 | + if ($styles['fill']) { |
|
| 686 | + $this->setFillColorArray($styles['fill']); |
|
| 687 | + $style .= 'F'; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + // Style : stroke |
|
| 691 | + if ($styles['stroke'] && $styles['stroke-width']) { |
|
| 692 | + $this->SetDrawColorArray($styles['stroke']); |
|
| 693 | + $this->SetLineWidth($styles['stroke-width']); |
|
| 694 | + $style .= 'D'; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + // Style : opacity |
|
| 698 | + if ($styles['fill-opacity']) { |
|
| 699 | + $this->SetAlpha($styles['fill-opacity']); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return $style; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * SVG - make a Rectangle |
|
| 707 | + * |
|
| 708 | + * @param float $x |
|
| 709 | + * @param float $y |
|
| 710 | + * @param float $w |
|
| 711 | + * @param float $h |
|
| 712 | + * @param string $style PDF Style |
|
| 713 | + * @access public |
|
| 714 | + */ |
|
| 715 | + public function svgRect($x, $y, $w, $h, $style) |
|
| 716 | + { |
|
| 717 | + // prepare the 4 corners |
|
| 718 | + $x1 = $x; |
|
| 719 | + $x2 = $x + $w; |
|
| 720 | + $x3 = $x + $w; |
|
| 721 | + $x4 = $x; |
|
| 722 | + |
|
| 723 | + $y1 = $y; |
|
| 724 | + $y2 = $y; |
|
| 725 | + $y3 = $y + $h; |
|
| 726 | + $y4 = $y + $h; |
|
| 727 | + |
|
| 728 | + // get the Closing operator from the PDF Style |
|
| 729 | + if ($style == 'F') $op = 'f'; |
|
| 730 | + elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 731 | + else $op = 'S'; |
|
| 732 | + |
|
| 733 | + // drawing |
|
| 734 | + $this->_Point($x1, $y1, true); |
|
| 735 | + $this->_Line($x2, $y2, true); |
|
| 736 | + $this->_Line($x3, $y3, true); |
|
| 737 | + $this->_Line($x4, $y4, true); |
|
| 738 | + $this->_Line($x1, $y1, true); |
|
| 739 | + $this->_out($op); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * SVG - make a Line |
|
| 744 | + * |
|
| 745 | + * @param float $x1 |
|
| 746 | + * @param float $y1 |
|
| 747 | + * @param float $x2 |
|
| 748 | + * @param float $y2 |
|
| 749 | + * @access public |
|
| 750 | + */ |
|
| 751 | + public function svgLine($x1, $y1, $x2, $y2) |
|
| 752 | + { |
|
| 753 | + // get the Closing operator |
|
| 754 | + $op = 'S'; |
|
| 755 | + |
|
| 756 | + // drawing |
|
| 757 | + $this->_Point($x1, $y1, true); |
|
| 758 | + $this->_Line($x2, $y2, true); |
|
| 759 | + $this->_out($op); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * SVG - make a Ellipse |
|
| 764 | + * |
|
| 765 | + * @param float $x0 x Center |
|
| 766 | + * @param float $y0 y Center |
|
| 767 | + * @param float $rx x radius |
|
| 768 | + * @param float $ry y radius |
|
| 769 | + * @param string $style PDF Style |
|
| 770 | + * @access public |
|
| 771 | + */ |
|
| 772 | + public function svgEllipse($x0, $y0, $rx, $ry, $style) |
|
| 773 | + { |
|
| 774 | + // get the Closing operator from the PDF Style |
|
| 775 | + if ($style == 'F') $op = 'f'; |
|
| 776 | + elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 777 | + else $op = 'S'; |
|
| 778 | + |
|
| 779 | + // drawing |
|
| 780 | + $this->_Arc($x0, $y0, $rx, $ry, 0, 2 * M_PI, true, true, true); |
|
| 781 | + $this->_out($op); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * SVG - make a Advanced Polygone |
|
| 786 | + * |
|
| 787 | + * @param array $actions list of actions |
|
| 788 | + * @param string $style PDF Style |
|
| 789 | + * @access public |
|
| 790 | + */ |
|
| 791 | + public function svgPolygone($actions, $style) |
|
| 792 | + { |
|
| 793 | + // get the Closing operator from the PDF Style |
|
| 794 | + if ($style == 'F') $op = 'f'; |
|
| 795 | + elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 796 | + else $op = 'S'; |
|
| 797 | + |
|
| 798 | + // To save the First action and the last point |
|
| 799 | + $first = array('', 0, 0); |
|
| 800 | + $last = array(0, 0, 0, 0); |
|
| 801 | + |
|
| 802 | + foreach ($actions as $action) { |
|
| 803 | + switch ($action[0]) |
|
| 804 | + { |
|
| 805 | + // Start the Path |
|
| 806 | + case 'M': |
|
| 807 | + case 'm': |
|
| 808 | + $first = $action; |
|
| 809 | + $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y; |
|
| 810 | + $this->_Point($x, $y, true); |
|
| 811 | + break; |
|
| 812 | + |
|
| 813 | + // Close the Path |
|
| 814 | + case 'Z': |
|
| 815 | + case 'z': |
|
| 816 | + $x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y; |
|
| 817 | + $this->_Line($x, $y, true); |
|
| 818 | + break; |
|
| 819 | + |
|
| 820 | + // Make a Line (new point) |
|
| 821 | + case 'L': |
|
| 822 | + $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y; |
|
| 823 | + $this->_Line($x, $y, true); |
|
| 824 | + break; |
|
| 825 | + |
|
| 826 | + // Make a Line (vector from last point) |
|
| 827 | + case 'l': |
|
| 828 | + $x = $last[0] + $action[1]; $y = $last[1] + $action[2]; $xc = $x; $yc = $y; |
|
| 829 | + $this->_Line($x, $y, true); |
|
| 830 | + break; |
|
| 831 | + |
|
| 832 | + // Make a Horizontal Line (new point) |
|
| 833 | + case 'H': |
|
| 834 | + $x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y; |
|
| 835 | + $this->_Line($x, $y, true); |
|
| 836 | + break; |
|
| 837 | + |
|
| 838 | + // Make a Horisontal Line (vector from last point) |
|
| 839 | + case 'h': |
|
| 840 | + $x = $last[0] + $action[1]; $y = $last[1]; $xc = $x; $yc = $y; |
|
| 841 | + $this->_Line($x, $y, true); |
|
| 842 | + break; |
|
| 843 | + |
|
| 844 | + // Make a Vertical Line (new point) |
|
| 845 | + case 'V': |
|
| 846 | + $x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y; |
|
| 847 | + $this->_Line($x, $y, true); |
|
| 848 | + break; |
|
| 849 | + |
|
| 850 | + // Make a Vertical Line (vector from last point) |
|
| 851 | + case 'v': |
|
| 852 | + $x = $last[0]; $y = $last[1] + $action[1]; $xc = $x; $yc = $y; |
|
| 853 | + $this->_Line($x, $y, true); |
|
| 854 | + break; |
|
| 855 | + |
|
| 856 | + // Make a Arc (new point) |
|
| 857 | + case 'A': |
|
| 858 | + $rx = $action[1]; // rx |
|
| 859 | + $ry = $action[2]; // ry |
|
| 860 | + $a = $action[3]; // deviation angle of the axis X |
|
| 861 | + $l = $action[4]; // large-arc-flag |
|
| 862 | + $s = $action[5]; // sweep-flag |
|
| 863 | + $x1 = $last[0]; // begin x |
|
| 864 | + $y1 = $last[1]; // begin y |
|
| 865 | + $x2 = $action[6]; // final x |
|
| 866 | + $y2 = $action[7]; // final y |
|
| 867 | + |
|
| 868 | + $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true); |
|
| 869 | + $x = $x2; $y = $y2; $xc = $x; $yc = $y; |
|
| 870 | + break; |
|
| 871 | + |
|
| 872 | + // Make a Arc (vector from last point) |
|
| 873 | + case 'a': |
|
| 874 | + $rx = $action[1]; // rx |
|
| 875 | + $ry = $action[2]; // ry |
|
| 876 | + $a = $action[3]; // deviation angle of the axis X |
|
| 877 | + $l = $action[4]; // large-arc-flag |
|
| 878 | + $s = $action[5]; // sweep-flag |
|
| 879 | + $x1 = $last[0]; // begin x |
|
| 880 | + $y1 = $last[1]; // begin y |
|
| 881 | + $x2 = $last[0] + $action[6]; // final x |
|
| 882 | + $y2 = $last[1] + $action[7]; // final y |
|
| 883 | + |
|
| 884 | + $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true); |
|
| 885 | + $x = $x2; $y = $y2; $xc = $x; $yc = $y; |
|
| 886 | + break; |
|
| 887 | + |
|
| 888 | + // Make a Bezier Curve (new point) |
|
| 889 | + case 'C': |
|
| 890 | + $x1 = $action[1]; |
|
| 891 | + $y1 = $action[2]; |
|
| 892 | + $x2 = $action[3]; |
|
| 893 | + $y2 = $action[4]; |
|
| 894 | + $xf = $action[5]; |
|
| 895 | + $yf = $action[6]; |
|
| 896 | + $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true); |
|
| 897 | + $x = $xf; $y = $yf; $xc = $x2; $yc = $y2; |
|
| 898 | + break; |
|
| 899 | + |
|
| 900 | + // Make a Bezier Curve (vector from last point) |
|
| 901 | + case 'c': |
|
| 902 | + $x1 = $last[0] + $action[1]; |
|
| 903 | + $y1 = $last[1] + $action[2]; |
|
| 904 | + $x2 = $last[0] + $action[3]; |
|
| 905 | + $y2 = $last[1] + $action[4]; |
|
| 906 | + $xf = $last[0] + $action[5]; |
|
| 907 | + $yf = $last[1] + $action[6]; |
|
| 908 | + $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true); |
|
| 909 | + $x = $xf; $y = $yf; $xc = $x2; $yc = $y2; |
|
| 910 | + break; |
|
| 911 | + |
|
| 912 | + // Unknown Path |
|
| 913 | + default: |
|
| 914 | + throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown'); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + // save the last point |
|
| 918 | + $last = array($x, $y, $xc, $yc); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + // finish the path |
|
| 922 | + $this->_out($op); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * SVG - go to a point |
|
| 927 | + * |
|
| 928 | + * @param float $x |
|
| 929 | + * @param float $y |
|
| 930 | + * @param boolean $trans apply transformation |
|
| 931 | + * @access protected |
|
| 932 | + */ |
|
| 933 | + protected function _Point($x, $y, $trans = false) |
|
| 934 | + { |
|
| 935 | + if ($trans) { |
|
| 936 | + $this->ptTransform($x, $y); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + $this->_out(sprintf('%.2F %.2F m', $x, $y)); |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * SVG - make a line from the last point to (x,y) |
|
| 944 | + * |
|
| 945 | + * @param float $x |
|
| 946 | + * @param float $y |
|
| 947 | + * @param boolean $trans apply transformation |
|
| 948 | + * @access protected |
|
| 949 | + */ |
|
| 950 | + protected function _Line($x, $y, $trans = false) |
|
| 951 | + { |
|
| 952 | + if ($trans) { |
|
| 953 | + $this->ptTransform($x, $y); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + $this->_out(sprintf('%.2F %.2F l', $x, $y)); |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2) |
|
| 961 | + * |
|
| 962 | + * @param float $x1 |
|
| 963 | + * @param float $y1 |
|
| 964 | + * @param float $x2 |
|
| 965 | + * @param float $y2 |
|
| 966 | + * @param float $xf |
|
| 967 | + * @param float $yf |
|
| 968 | + * @param boolean $trans apply transformation |
|
| 969 | + * @access protected |
|
| 970 | + */ |
|
| 971 | + protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false) |
|
| 972 | + { |
|
| 973 | + if ($trans) { |
|
| 974 | + $this->ptTransform($x1, $y1); |
|
| 975 | + $this->ptTransform($x2, $y2); |
|
| 976 | + $this->ptTransform($xf, $yf); |
|
| 977 | + } |
|
| 978 | + $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf)); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * SVG - make a arc with Center, Radius, from angleBegin to angleEnd |
|
| 983 | + * |
|
| 984 | + * @param float $xc |
|
| 985 | + * @param float $yc |
|
| 986 | + * @param float $rx |
|
| 987 | + * @param float $ry |
|
| 988 | + * @param float $angleBegin in radians |
|
| 989 | + * @param float $angleEnd in radians |
|
| 990 | + * @param boolean $direction |
|
| 991 | + * @param boolean $drawFirst, true => add the first point |
|
| 992 | + * @param boolean $trans apply transformation |
|
| 993 | + * @access protected |
|
| 994 | + */ |
|
| 995 | + protected function _Arc( |
|
| 996 | + $xc, |
|
| 997 | + $yc, |
|
| 998 | + $rx, |
|
| 999 | + $ry, |
|
| 1000 | + $angleBegin, |
|
| 1001 | + $angleEnd, |
|
| 1002 | + $direction = true, |
|
| 1003 | + $drawFirst = true, |
|
| 1004 | + $trans = false) |
|
| 1005 | + { |
|
| 1006 | + // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction |
|
| 1007 | + if ( ! $direction) $angleBegin += M_PI * 2.; |
|
| 1008 | + |
|
| 1009 | + // cut in segment to convert in berize curv |
|
| 1010 | + $dt = ($angleEnd - $angleBegin) / self::ARC_NB_SEGMENT; |
|
| 1011 | + $dtm = $dt / 3; |
|
| 1012 | + |
|
| 1013 | + // center of the arc |
|
| 1014 | + $x0 = $xc; $y0 = $yc; |
|
| 1015 | + |
|
| 1016 | + // calculing the first point |
|
| 1017 | + $t1 = $angleBegin; |
|
| 1018 | + $a0 = $x0 + ($rx * cos($t1)); |
|
| 1019 | + $b0 = $y0 + ($ry * sin($t1)); |
|
| 1020 | + $c0 = -$rx * sin($t1); |
|
| 1021 | + $d0 = $ry * cos($t1); |
|
| 1022 | + |
|
| 1023 | + // if drawFirst => draw the first point |
|
| 1024 | + if ($drawFirst) { |
|
| 1025 | + $this->_Point($a0, $b0, $trans); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + // foreach segment |
|
| 1029 | + for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) { |
|
| 1030 | + // calculing the next point |
|
| 1031 | + $t1 = ($i * $dt) + $angleBegin; |
|
| 1032 | + $a1 = $x0 + ($rx * cos($t1)); |
|
| 1033 | + $b1 = $y0 + ($ry * sin($t1)); |
|
| 1034 | + $c1 = -$rx * sin($t1); |
|
| 1035 | + $d1 = $ry * cos($t1); |
|
| 1036 | + |
|
| 1037 | + // make the bezier curv |
|
| 1038 | + $this->_Curve( |
|
| 1039 | + $a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm), |
|
| 1040 | + $a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm), |
|
| 1041 | + $a1, $b1, |
|
| 1042 | + $trans |
|
| 1043 | + ); |
|
| 1044 | + |
|
| 1045 | + // save the point |
|
| 1046 | + $a0 = $a1; |
|
| 1047 | + $b0 = $b1; |
|
| 1048 | + $c0 = $c1; |
|
| 1049 | + $d0 = $d1; |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * SVG - make a arc from Pt1 to Pt2, with Radius |
|
| 1055 | + * |
|
| 1056 | + * @param float $x1 |
|
| 1057 | + * @param float $y1 |
|
| 1058 | + * @param float $x2 |
|
| 1059 | + * @param float $y2 |
|
| 1060 | + * @param float $rx |
|
| 1061 | + * @param float $ry |
|
| 1062 | + * @param float $angle deviation angle of the axis X |
|
| 1063 | + * @param integer $l large-arc-flag |
|
| 1064 | + * @param integer $s sweep-flag |
|
| 1065 | + * @param boolean $trans apply transformation |
|
| 1066 | + * @access protected |
|
| 1067 | + */ |
|
| 1068 | + protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s = 0, $trans = false) |
|
| 1069 | + { |
|
| 1070 | + // array to stock the parameters |
|
| 1071 | + $v = array(); |
|
| 1072 | + |
|
| 1073 | + // the original values |
|
| 1074 | + $v['x1'] = $x1; |
|
| 1075 | + $v['y1'] = $y1; |
|
| 1076 | + $v['x2'] = $x2; |
|
| 1077 | + $v['y2'] = $y2; |
|
| 1078 | + $v['rx'] = $rx; |
|
| 1079 | + $v['ry'] = $ry; |
|
| 1080 | + |
|
| 1081 | + // rotate with the deviation angle of the axis X |
|
| 1082 | + $v['xr1'] = $v['x1'] * cos($angle) - $v['y1'] * sin($angle); |
|
| 1083 | + $v['yr1'] = $v['x1'] * sin($angle) + $v['y1'] * cos($angle); |
|
| 1084 | + $v['xr2'] = $v['x2'] * cos($angle) - $v['y2'] * sin($angle); |
|
| 1085 | + $v['yr2'] = $v['x2'] * sin($angle) + $v['y2'] * cos($angle); |
|
| 1086 | + |
|
| 1087 | + // the normalized vector |
|
| 1088 | + $v['Xr1'] = $v['xr1'] / $v['rx']; |
|
| 1089 | + $v['Yr1'] = $v['yr1'] / $v['ry']; |
|
| 1090 | + $v['Xr2'] = $v['xr2'] / $v['rx']; |
|
| 1091 | + $v['Yr2'] = $v['yr2'] / $v['ry']; |
|
| 1092 | + $v['dXr'] = $v['Xr2'] - $v['Xr1']; |
|
| 1093 | + $v['dYr'] = $v['Yr2'] - $v['Yr1']; |
|
| 1094 | + $v['D'] = $v['dXr'] * $v['dXr'] + $v['dYr'] * $v['dYr']; |
|
| 1095 | + |
|
| 1096 | + // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line |
|
| 1097 | + if ($v['D'] == 0 || $v['D'] > 4) { |
|
| 1098 | + $this->_Line($x2, $y2, $trans); |
|
| 1099 | + return false; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd |
|
| 1103 | + $v['s1'] = array(); |
|
| 1104 | + $v['s1']['t'] = sqrt((4. - $v['D']) / $v['D']); |
|
| 1105 | + $v['s1']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s1']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.; |
|
| 1106 | + $v['s1']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s1']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.; |
|
| 1107 | + $v['s1']['xr'] = $v['s1']['Xr'] * $v['rx']; |
|
| 1108 | + $v['s1']['yr'] = $v['s1']['Yr'] * $v['ry']; |
|
| 1109 | + $v['s1']['x'] = $v['s1']['xr'] * cos($angle) + $v['s1']['yr'] * sin($angle); |
|
| 1110 | + $v['s1']['y'] = -$v['s1']['xr'] * sin($angle) + $v['s1']['yr'] * cos($angle); |
|
| 1111 | + $v['s1']['a1'] = atan2($v['y1'] - $v['s1']['y'], $v['x1'] - $v['s1']['x']); |
|
| 1112 | + $v['s1']['a2'] = atan2($v['y2'] - $v['s1']['y'], $v['x2'] - $v['s1']['x']); |
|
| 1113 | + if ($v['s1']['a1'] > $v['s1']['a2']) $v['s1']['a1'] -= 2 * M_PI; |
|
| 1114 | + |
|
| 1115 | + $v['s2'] = array(); |
|
| 1116 | + $v['s2']['t'] = -$v['s1']['t']; |
|
| 1117 | + $v['s2']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s2']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.; |
|
| 1118 | + $v['s2']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s2']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.; |
|
| 1119 | + $v['s2']['xr'] = $v['s2']['Xr'] * $v['rx']; |
|
| 1120 | + $v['s2']['yr'] = $v['s2']['Yr'] * $v['ry']; |
|
| 1121 | + $v['s2']['x'] = $v['s2']['xr'] * cos($angle) + $v['s2']['yr'] * sin($angle); |
|
| 1122 | + $v['s2']['y'] = -$v['s2']['xr'] * sin($angle) + $v['s2']['yr'] * cos($angle); |
|
| 1123 | + $v['s2']['a1'] = atan2($v['y1'] - $v['s2']['y'], $v['x1'] - $v['s2']['x']); |
|
| 1124 | + $v['s2']['a2'] = atan2($v['y2'] - $v['s2']['y'], $v['x2'] - $v['s2']['x']); |
|
| 1125 | + if ($v['s2']['a1'] > $v['s2']['a2']) $v['s2']['a1'] -= 2 * M_PI; |
|
| 1126 | + |
|
| 1127 | + if ( ! $l) { |
|
| 1128 | + if ($s) { |
|
| 1129 | + $xc = $v['s2']['x']; |
|
| 1130 | + $yc = $v['s2']['y']; |
|
| 1131 | + $a1 = $v['s2']['a1']; |
|
| 1132 | + $a2 = $v['s2']['a2']; |
|
| 1133 | + $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans); |
|
| 1134 | + } else { |
|
| 1135 | + $xc = $v['s1']['x']; |
|
| 1136 | + $yc = $v['s1']['y']; |
|
| 1137 | + $a1 = $v['s1']['a1']; |
|
| 1138 | + $a2 = $v['s1']['a2']; |
|
| 1139 | + $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans); |
|
| 1140 | + } |
|
| 1141 | + } else { |
|
| 1142 | + if ($s) { |
|
| 1143 | + $xc = $v['s1']['x']; |
|
| 1144 | + $yc = $v['s1']['y']; |
|
| 1145 | + $a1 = $v['s1']['a1']; |
|
| 1146 | + $a2 = $v['s1']['a2']; |
|
| 1147 | + $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans); |
|
| 1148 | + } else { |
|
| 1149 | + $xc = $v['s2']['x']; |
|
| 1150 | + $yc = $v['s2']['y']; |
|
| 1151 | + $a1 = $v['s2']['a1']; |
|
| 1152 | + $a2 = $v['s2']['a2']; |
|
| 1153 | + $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * SVG - transform the point (reference) |
|
| 1160 | + * |
|
| 1161 | + * @param float &$x |
|
| 1162 | + * @param float &$y |
|
| 1163 | + * @param boolean $trans true => convert into PDF unit |
|
| 1164 | + * @param double $x |
|
| 1165 | + * @param double $y |
|
| 1166 | + * @return boolean |
|
| 1167 | + * @access public |
|
| 1168 | + */ |
|
| 1169 | + public function ptTransform(&$x, &$y, $trans = true) |
|
| 1170 | + { |
|
| 1171 | + // load the last Transfomation Matrix |
|
| 1172 | + $nb = count($this->_transf); |
|
| 1173 | + if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1174 | + else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1175 | + |
|
| 1176 | + // apply the Transformation Matrix |
|
| 1177 | + list($x, $y) = array(($x * $m[0] + $y * $m[2] + $m[4]), ($x * $m[1] + $y * $m[3] + $m[5])); |
|
| 1178 | + |
|
| 1179 | + // if true => convert into PDF unit |
|
| 1180 | + if ($trans) { |
|
| 1181 | + $x = $x * $this->k; |
|
| 1182 | + $y = ($this->h - $y) * $this->k; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + return true; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + /** |
|
| 1189 | + * SVG - add a transformation Matric |
|
| 1190 | + * |
|
| 1191 | + * @param array $n matrix |
|
| 1192 | + * @access public |
|
| 1193 | + */ |
|
| 1194 | + public function doTransform($n = null) |
|
| 1195 | + { |
|
| 1196 | + // get the last Transformation Matrix |
|
| 1197 | + $nb = count($this->_transf); |
|
| 1198 | + if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1199 | + else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1200 | + |
|
| 1201 | + // if no transform, get the Identity Matrix |
|
| 1202 | + if ( ! $n) $n = array(1, 0, 0, 1, 0, 0); |
|
| 1203 | + |
|
| 1204 | + // create the new Transformation Matrix |
|
| 1205 | + $this->_transf[] = array( |
|
| 1206 | + $m[0] * $n[0] + $m[2] * $n[1], |
|
| 1207 | + $m[1] * $n[0] + $m[3] * $n[1], |
|
| 1208 | + $m[0] * $n[2] + $m[2] * $n[3], |
|
| 1209 | + $m[1] * $n[2] + $m[3] * $n[3], |
|
| 1210 | + $m[0] * $n[4] + $m[2] * $n[5] + $m[4], |
|
| 1211 | + $m[1] * $n[4] + $m[3] * $n[5] + $m[5] |
|
| 1212 | + ); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * SVG - remove a transformation Matric |
|
| 1217 | + * |
|
| 1218 | + * @access public |
|
| 1219 | + */ |
|
| 1220 | + public function undoTransform() |
|
| 1221 | + { |
|
| 1222 | + array_pop($this->_transf); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * Convert a HTML2PDF barcode in a TCPDF barcode |
|
| 1227 | + * |
|
| 1228 | + * @param string $code code to print |
|
| 1229 | + * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats) |
|
| 1230 | + * @param int $x x position in user units |
|
| 1231 | + * @param int $y y position in user units |
|
| 1232 | + * @param int $w width in user units |
|
| 1233 | + * @param int $h height in user units |
|
| 1234 | + * @param int $labelFontsize of the Test Label. If false : no Label |
|
| 1235 | + * @param array $color color of the foreground |
|
| 1236 | + * @access public |
|
| 1237 | + */ |
|
| 1238 | + public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color) |
|
| 1239 | + { |
|
| 1240 | + // the style of the barcode |
|
| 1241 | + $style = array( |
|
| 1242 | + 'position' => 'S', |
|
| 1243 | + 'text' => ($labelFontsize ? true : false), |
|
| 1244 | + 'fgcolor' => $color, |
|
| 1245 | + 'bgcolor' => false, |
|
| 1246 | + ); |
|
| 1247 | + |
|
| 1248 | + // build the barcode |
|
| 1249 | + $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N'); |
|
| 1250 | + |
|
| 1251 | + // it Label => add the FontSize to the height |
|
| 1252 | + if ($labelFontsize) $h += ($labelFontsize); |
|
| 1253 | + |
|
| 1254 | + // return the size of the barcode |
|
| 1255 | + return array($w, $h); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * create a automatic Index on a page |
|
| 1260 | + * |
|
| 1261 | + * @param html2pdf $obj parent object |
|
| 1262 | + * @param string $titre Title of the Index Page |
|
| 1263 | + * @param integer $sizeTitle Font size for hthe Title |
|
| 1264 | + * @param integer $sizeBookmark Font size for the bookmarks |
|
| 1265 | + * @param boolean $bookmarkTitle Bookmark the Title |
|
| 1266 | + * @param boolean $displayPage Display the page number for each bookmark |
|
| 1267 | + * @param integer $page draw the automatic Index on a specific Page. if null => add a page at the end |
|
| 1268 | + * @param string $fontName FontName to use |
|
| 1269 | + * @access public |
|
| 1270 | + */ |
|
| 1271 | + public function createIndex( |
|
| 1272 | + &$obj, |
|
| 1273 | + $titre = 'Index', |
|
| 1274 | + $sizeTitle = 20, |
|
| 1275 | + $sizeBookmark = 15, |
|
| 1276 | + $bookmarkTitle = true, |
|
| 1277 | + $displayPage = true, |
|
| 1278 | + $page = null, |
|
| 1279 | + $fontName = 'helvetica') |
|
| 1280 | + { |
|
| 1281 | + // bookmark the Title if wanted |
|
| 1282 | + if ($bookmarkTitle) { |
|
| 1283 | + $this->Bookmark($titre, 0, -1); |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + // display the Title with the good Font size |
|
| 1287 | + $this->SetFont($fontName, '', $sizeTitle); |
|
| 1288 | + $this->Cell(0, 5, $titre, 0, 1, 'C'); |
|
| 1289 | + |
|
| 1290 | + // set the good Font size for the bookmarks |
|
| 1291 | + $this->SetFont($fontName, '', $sizeBookmark); |
|
| 1292 | + $this->Ln(10); |
|
| 1293 | + |
|
| 1294 | + // get the number of bookmarks |
|
| 1295 | + $size = sizeof($this->outlines); |
|
| 1296 | + |
|
| 1297 | + // get the size of the "P. xx" cell |
|
| 1298 | + $pageCellSize = $this->GetStringWidth('p. '.$this->outlines[$size - 1]['p']) + 2; |
|
| 1299 | + |
|
| 1300 | + // Foreach bookmark |
|
| 1301 | + for ($i = 0; $i < $size; $i++) { |
|
| 1302 | + // if we need a new page => add a new page |
|
| 1303 | + if ($this->getY() + $this->FontSize >= ($this->h - $this->bMargin)) { |
|
| 1304 | + $obj->_INDEX_NewPage($page); |
|
| 1305 | + $this->SetFont($fontName, '', $sizeBookmark); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + // Offset of the current level |
|
| 1309 | + $level = $this->outlines[$i]['l']; |
|
| 1310 | + if ($level > 0) $this->Cell($level * 8); |
|
| 1311 | + |
|
| 1312 | + // Caption (cut to fit on the width page) |
|
| 1313 | + $str = $this->outlines[$i]['t']; |
|
| 1314 | + $strsize = $this->GetStringWidth($str); |
|
| 1315 | + $availableSize = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - 4; |
|
| 1316 | + while ($strsize >= $availableSize) { |
|
| 1317 | + $str = substr($str, 0, -1); |
|
| 1318 | + $strsize = $this->GetStringWidth($str); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + // if we want to display the page nmber |
|
| 1322 | + if ($displayPage) { |
|
| 1323 | + // display the Bookmark Caption |
|
| 1324 | + $this->Cell($strsize + 2, $this->FontSize + 2, $str); |
|
| 1325 | + |
|
| 1326 | + //Filling dots |
|
| 1327 | + $w = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - ($strsize + 2); |
|
| 1328 | + $nb = $w / $this->GetStringWidth('.'); |
|
| 1329 | + $dots = str_repeat('.', $nb); |
|
| 1330 | + $this->Cell($w, $this->FontSize + 2, $dots, 0, 0, 'R'); |
|
| 1331 | + |
|
| 1332 | + //Page number |
|
| 1333 | + $this->Cell($pageCellSize, $this->FontSize + 2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R'); |
|
| 1334 | + } else { |
|
| 1335 | + // display the Bookmark Caption |
|
| 1336 | + $this->Cell($strsize + 2, $this->FontSize + 2, $str, 0, 1); |
|
| 1337 | + } |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Returns the string alias used for the total number of pages. |
|
| 1343 | + * |
|
| 1344 | + * @access public |
|
| 1345 | + * @return string; |
|
| 1346 | + * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias() |
|
| 1347 | + */ |
|
| 1348 | + public function getMyAliasNbPages() |
|
| 1349 | + { |
|
| 1350 | + if ($this->_myLastPageGroupNb == 0) { |
|
| 1351 | + return $this->getAliasNbPages(); |
|
| 1352 | + } else { |
|
| 1353 | + $old = $this->currpagegroup; |
|
| 1354 | + $this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}'; |
|
| 1355 | + $new = $this->getPageGroupAlias(); |
|
| 1356 | + $this->currpagegroup = $old; |
|
| 1357 | + |
|
| 1358 | + return $new; |
|
| 1359 | + } |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Returns the current page number. |
|
| 1364 | + * |
|
| 1365 | + * @access public |
|
| 1366 | + * @param integer $page |
|
| 1367 | + * @return integer; |
|
| 1368 | + */ |
|
| 1369 | + public function getMyNumPage($page = null) |
|
| 1370 | + { |
|
| 1371 | + if ($page === null) { |
|
| 1372 | + $page = $this->page; |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + if ($this->_myLastPageGroupNb == 0) { |
|
| 1376 | + return $page; |
|
| 1377 | + } else { |
|
| 1378 | + return $page - $this->_myLastPageGroup; |
|
| 1379 | + } |
|
| 1380 | + } |
|
| 1381 | + |
|
| 1382 | + /** |
|
| 1383 | + * Start a new group of pages |
|
| 1384 | + * |
|
| 1385 | + * @access public |
|
| 1386 | + * @return integer; |
|
| 1387 | + * @see tcpdf::startPageGroup |
|
| 1388 | + */ |
|
| 1389 | + public function myStartPageGroup() |
|
| 1390 | + { |
|
| 1391 | + $this->_myLastPageGroup = $this->page - 1; |
|
| 1392 | + $this->_myLastPageGroupNb++; |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + /** |
|
| 1396 | + * get $_myLastPageGroup; |
|
| 1397 | + * |
|
| 1398 | + * @access public |
|
| 1399 | + * @return integer $_myLastPageGroup; |
|
| 1400 | + */ |
|
| 1401 | + public function getMyLastPageGroup() |
|
| 1402 | + { |
|
| 1403 | + return $this->_myLastPageGroup; |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * set $_myLastPageGroup; |
|
| 1408 | + * |
|
| 1409 | + * @access public |
|
| 1410 | + * @param integer $myLastPageGroup; |
|
| 1411 | + * @param integer $myLastPageGroup |
|
| 1412 | + */ |
|
| 1413 | + public function setMyLastPageGroup($myLastPageGroup) |
|
| 1414 | + { |
|
| 1415 | + $this->_myLastPageGroup = $myLastPageGroup; |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * get $_myLastPageGroupNb; |
|
| 1420 | + * |
|
| 1421 | + * @access public |
|
| 1422 | + * @return integer $_myLastPageGroupNb; |
|
| 1423 | + */ |
|
| 1424 | + public function getMyLastPageGroupNb() |
|
| 1425 | + { |
|
| 1426 | + return $this->_myLastPageGroupNb; |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * set $_myLastPageGroupNb; |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param integer $myLastPageGroupNb; |
|
| 1434 | + * @param integer $myLastPageGroupNb |
|
| 1435 | + */ |
|
| 1436 | + public function setMyLastPageGroupNb($myLastPageGroupNb) |
|
| 1437 | + { |
|
| 1438 | + $this->_myLastPageGroupNb = $myLastPageGroupNb; |
|
| 1439 | + } |
|
| 1440 | 1440 | } |
@@ -549,8 +549,12 @@ discard block |
||
| 549 | 549 | public function setRotation($angle, $xC = null, $yC = null) |
| 550 | 550 | { |
| 551 | 551 | // if no center, rotate around the current posiition |
| 552 | - if ($xC === null) $xC = $this->x; |
|
| 553 | - if ($yC === null) $yC = $this->y; |
|
| 552 | + if ($xC === null) { |
|
| 553 | + $xC = $this->x; |
|
| 554 | + } |
|
| 555 | + if ($yC === null) { |
|
| 556 | + $yC = $this->y; |
|
| 557 | + } |
|
| 554 | 558 | |
| 555 | 559 | // prepare the coordinate |
| 556 | 560 | $yC = ($this->h - $yC) * $this->k; |
@@ -592,8 +596,9 @@ discard block |
||
| 592 | 596 | */ |
| 593 | 597 | public function SetY($y, $resetx = true, $rtloff = false) |
| 594 | 598 | { |
| 595 | - if ($resetx) |
|
| 596 | - $this->x = $this->lMargin; |
|
| 599 | + if ($resetx) { |
|
| 600 | + $this->x = $this->lMargin; |
|
| 601 | + } |
|
| 597 | 602 | |
| 598 | 603 | $this->y = $y; |
| 599 | 604 | } |
@@ -726,9 +731,13 @@ discard block |
||
| 726 | 731 | $y4 = $y + $h; |
| 727 | 732 | |
| 728 | 733 | // get the Closing operator from the PDF Style |
| 729 | - if ($style == 'F') $op = 'f'; |
|
| 730 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 731 | - else $op = 'S'; |
|
| 734 | + if ($style == 'F') { |
|
| 735 | + $op = 'f'; |
|
| 736 | + } elseif ($style == 'FD' || $style == 'DF') { |
|
| 737 | + $op = 'B'; |
|
| 738 | + } else { |
|
| 739 | + $op = 'S'; |
|
| 740 | + } |
|
| 732 | 741 | |
| 733 | 742 | // drawing |
| 734 | 743 | $this->_Point($x1, $y1, true); |
@@ -772,9 +781,13 @@ discard block |
||
| 772 | 781 | public function svgEllipse($x0, $y0, $rx, $ry, $style) |
| 773 | 782 | { |
| 774 | 783 | // get the Closing operator from the PDF Style |
| 775 | - if ($style == 'F') $op = 'f'; |
|
| 776 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 777 | - else $op = 'S'; |
|
| 784 | + if ($style == 'F') { |
|
| 785 | + $op = 'f'; |
|
| 786 | + } elseif ($style == 'FD' || $style == 'DF') { |
|
| 787 | + $op = 'B'; |
|
| 788 | + } else { |
|
| 789 | + $op = 'S'; |
|
| 790 | + } |
|
| 778 | 791 | |
| 779 | 792 | // drawing |
| 780 | 793 | $this->_Arc($x0, $y0, $rx, $ry, 0, 2 * M_PI, true, true, true); |
@@ -791,9 +804,13 @@ discard block |
||
| 791 | 804 | public function svgPolygone($actions, $style) |
| 792 | 805 | { |
| 793 | 806 | // get the Closing operator from the PDF Style |
| 794 | - if ($style == 'F') $op = 'f'; |
|
| 795 | - elseif ($style == 'FD' || $style == 'DF') $op = 'B'; |
|
| 796 | - else $op = 'S'; |
|
| 807 | + if ($style == 'F') { |
|
| 808 | + $op = 'f'; |
|
| 809 | + } elseif ($style == 'FD' || $style == 'DF') { |
|
| 810 | + $op = 'B'; |
|
| 811 | + } else { |
|
| 812 | + $op = 'S'; |
|
| 813 | + } |
|
| 797 | 814 | |
| 798 | 815 | // To save the First action and the last point |
| 799 | 816 | $first = array('', 0, 0); |
@@ -1004,7 +1021,9 @@ discard block |
||
| 1004 | 1021 | $trans = false) |
| 1005 | 1022 | { |
| 1006 | 1023 | // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction |
| 1007 | - if ( ! $direction) $angleBegin += M_PI * 2.; |
|
| 1024 | + if ( ! $direction) { |
|
| 1025 | + $angleBegin += M_PI * 2.; |
|
| 1026 | + } |
|
| 1008 | 1027 | |
| 1009 | 1028 | // cut in segment to convert in berize curv |
| 1010 | 1029 | $dt = ($angleEnd - $angleBegin) / self::ARC_NB_SEGMENT; |
@@ -1110,7 +1129,9 @@ discard block |
||
| 1110 | 1129 | $v['s1']['y'] = -$v['s1']['xr'] * sin($angle) + $v['s1']['yr'] * cos($angle); |
| 1111 | 1130 | $v['s1']['a1'] = atan2($v['y1'] - $v['s1']['y'], $v['x1'] - $v['s1']['x']); |
| 1112 | 1131 | $v['s1']['a2'] = atan2($v['y2'] - $v['s1']['y'], $v['x2'] - $v['s1']['x']); |
| 1113 | - if ($v['s1']['a1'] > $v['s1']['a2']) $v['s1']['a1'] -= 2 * M_PI; |
|
| 1132 | + if ($v['s1']['a1'] > $v['s1']['a2']) { |
|
| 1133 | + $v['s1']['a1'] -= 2 * M_PI; |
|
| 1134 | + } |
|
| 1114 | 1135 | |
| 1115 | 1136 | $v['s2'] = array(); |
| 1116 | 1137 | $v['s2']['t'] = -$v['s1']['t']; |
@@ -1122,7 +1143,9 @@ discard block |
||
| 1122 | 1143 | $v['s2']['y'] = -$v['s2']['xr'] * sin($angle) + $v['s2']['yr'] * cos($angle); |
| 1123 | 1144 | $v['s2']['a1'] = atan2($v['y1'] - $v['s2']['y'], $v['x1'] - $v['s2']['x']); |
| 1124 | 1145 | $v['s2']['a2'] = atan2($v['y2'] - $v['s2']['y'], $v['x2'] - $v['s2']['x']); |
| 1125 | - if ($v['s2']['a1'] > $v['s2']['a2']) $v['s2']['a1'] -= 2 * M_PI; |
|
| 1146 | + if ($v['s2']['a1'] > $v['s2']['a2']) { |
|
| 1147 | + $v['s2']['a1'] -= 2 * M_PI; |
|
| 1148 | + } |
|
| 1126 | 1149 | |
| 1127 | 1150 | if ( ! $l) { |
| 1128 | 1151 | if ($s) { |
@@ -1170,8 +1193,11 @@ discard block |
||
| 1170 | 1193 | { |
| 1171 | 1194 | // load the last Transfomation Matrix |
| 1172 | 1195 | $nb = count($this->_transf); |
| 1173 | - if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1174 | - else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1196 | + if ($nb) { |
|
| 1197 | + $m = $this->_transf[$nb - 1]; |
|
| 1198 | + } else { |
|
| 1199 | + $m = array(1, 0, 0, 1, 0, 0); |
|
| 1200 | + } |
|
| 1175 | 1201 | |
| 1176 | 1202 | // apply the Transformation Matrix |
| 1177 | 1203 | list($x, $y) = array(($x * $m[0] + $y * $m[2] + $m[4]), ($x * $m[1] + $y * $m[3] + $m[5])); |
@@ -1195,11 +1221,16 @@ discard block |
||
| 1195 | 1221 | { |
| 1196 | 1222 | // get the last Transformation Matrix |
| 1197 | 1223 | $nb = count($this->_transf); |
| 1198 | - if ($nb) $m = $this->_transf[$nb - 1]; |
|
| 1199 | - else $m = array(1, 0, 0, 1, 0, 0); |
|
| 1224 | + if ($nb) { |
|
| 1225 | + $m = $this->_transf[$nb - 1]; |
|
| 1226 | + } else { |
|
| 1227 | + $m = array(1, 0, 0, 1, 0, 0); |
|
| 1228 | + } |
|
| 1200 | 1229 | |
| 1201 | 1230 | // if no transform, get the Identity Matrix |
| 1202 | - if ( ! $n) $n = array(1, 0, 0, 1, 0, 0); |
|
| 1231 | + if ( ! $n) { |
|
| 1232 | + $n = array(1, 0, 0, 1, 0, 0); |
|
| 1233 | + } |
|
| 1203 | 1234 | |
| 1204 | 1235 | // create the new Transformation Matrix |
| 1205 | 1236 | $this->_transf[] = array( |
@@ -1249,7 +1280,9 @@ discard block |
||
| 1249 | 1280 | $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N'); |
| 1250 | 1281 | |
| 1251 | 1282 | // it Label => add the FontSize to the height |
| 1252 | - if ($labelFontsize) $h += ($labelFontsize); |
|
| 1283 | + if ($labelFontsize) { |
|
| 1284 | + $h += ($labelFontsize); |
|
| 1285 | + } |
|
| 1253 | 1286 | |
| 1254 | 1287 | // return the size of the barcode |
| 1255 | 1288 | return array($w, $h); |
@@ -1307,7 +1340,9 @@ discard block |
||
| 1307 | 1340 | |
| 1308 | 1341 | // Offset of the current level |
| 1309 | 1342 | $level = $this->outlines[$i]['l']; |
| 1310 | - if ($level > 0) $this->Cell($level * 8); |
|
| 1343 | + if ($level > 0) { |
|
| 1344 | + $this->Cell($level * 8); |
|
| 1345 | + } |
|
| 1311 | 1346 | |
| 1312 | 1347 | // Caption (cut to fit on the width page) |
| 1313 | 1348 | $str = $this->outlines[$i]['t']; |
@@ -43,6 +43,7 @@ |
||
| 43 | 43 | * Set the HTML2PDF parent object |
| 44 | 44 | * |
| 45 | 45 | * @param &HTML2PDF reference to the HTML2PDF parent $object |
| 46 | + * @param HTML2PDF_myPdf|null $pdf |
|
| 46 | 47 | * @access public |
| 47 | 48 | */ |
| 48 | 49 | public function setPdfParent(&$pdf) |
@@ -11,1849 +11,1849 @@ |
||
| 11 | 11 | |
| 12 | 12 | class HTML2PDF_parsingCss |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * reference to the pdf object |
|
| 16 | - * @var TCPDF |
|
| 17 | - */ |
|
| 18 | - protected $_pdf = null; |
|
| 19 | - |
|
| 20 | - protected $_htmlColor = array(); // list of the HTML colors |
|
| 21 | - protected $_onlyLeft = false; // flag if we are in a sub html => only "text-align:left" is used |
|
| 22 | - protected $_defaultFont = null; // default font to use if the asked font does not exist |
|
| 23 | - |
|
| 24 | - public $value = array(); // current values |
|
| 25 | - public $css = array(); // css values |
|
| 26 | - public $cssKeys = array(); // css key, for the execution order |
|
| 27 | - public $table = array(); // level history |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Constructor |
|
| 31 | - * |
|
| 32 | - * @param &HTML2PDF_myPdf reference to the PDF $object |
|
| 33 | - * @param HTML2PDF_myPdf $pdf |
|
| 34 | - * @access public |
|
| 35 | - */ |
|
| 36 | - public function __construct(&$pdf) |
|
| 37 | - { |
|
| 38 | - $this->_init(); |
|
| 39 | - $this->setPdfParent($pdf); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Set the HTML2PDF parent object |
|
| 44 | - * |
|
| 45 | - * @param &HTML2PDF reference to the HTML2PDF parent $object |
|
| 46 | - * @access public |
|
| 47 | - */ |
|
| 48 | - public function setPdfParent(&$pdf) |
|
| 49 | - { |
|
| 50 | - $this->_pdf = &$pdf; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Inform that we want only "test-align:left" because we are in a sub HTML |
|
| 55 | - * |
|
| 56 | - * @access public |
|
| 57 | - */ |
|
| 58 | - public function setOnlyLeft() |
|
| 59 | - { |
|
| 60 | - $this->value['text-align'] = 'left'; |
|
| 61 | - $this->_onlyLeft = true; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the vales of the parent, if exist |
|
| 66 | - * |
|
| 67 | - * @return array CSS values |
|
| 68 | - * @access public |
|
| 69 | - */ |
|
| 70 | - public function getOldValues() |
|
| 71 | - { |
|
| 72 | - return isset($this->table[count($this->table) - 1]) ? $this->table[count($this->table) - 1] : $this->value; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * define the Default Font to use, if the font does not exist, or if no font asked |
|
| 77 | - * |
|
| 78 | - * @param string default font-family. If null : Arial for no font asked, and error fot ont does not exist |
|
| 79 | - * @param string $default |
|
| 80 | - * @return string old default font-family |
|
| 81 | - * @access public |
|
| 82 | - */ |
|
| 83 | - public function setDefaultFont($default = null) |
|
| 84 | - { |
|
| 85 | - $old = $this->_defaultFont; |
|
| 86 | - $this->_defaultFont = $default; |
|
| 87 | - if ($default) { |
|
| 88 | - $this->value['font-family'] = $default; |
|
| 89 | - } |
|
| 90 | - return $old; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Init the object |
|
| 95 | - * |
|
| 96 | - * @access protected |
|
| 97 | - */ |
|
| 98 | - protected function _init() |
|
| 99 | - { |
|
| 100 | - // get the Web Colors from TCPDF |
|
| 101 | - require(K_PATH_MAIN.'htmlcolors.php'); |
|
| 102 | - $this->_htmlColor = $webcolor; |
|
| 103 | - |
|
| 104 | - // init the Style |
|
| 105 | - $this->table = array(); |
|
| 106 | - $this->value = array(); |
|
| 107 | - $this->initStyle(); |
|
| 108 | - |
|
| 109 | - // Init the styles without legacy |
|
| 110 | - $this->resetStyle(); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Init the CSS Style |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - */ |
|
| 118 | - public function initStyle() |
|
| 119 | - { |
|
| 120 | - $this->value['id_tag'] = 'body'; // tag name |
|
| 121 | - $this->value['id_name'] = null; // tag - attribute name |
|
| 122 | - $this->value['id_id'] = null; // tag - attribute id |
|
| 123 | - $this->value['id_class'] = null; // tag - attribute class |
|
| 124 | - $this->value['id_lst'] = array('*'); // tag - list of legacy |
|
| 125 | - $this->value['mini-size'] = 1.; // specific size report for sup, sub |
|
| 126 | - $this->value['mini-decal'] = 0; // specific position report for sup, sub |
|
| 127 | - $this->value['font-family'] = 'Arial'; |
|
| 128 | - $this->value['font-bold'] = false; |
|
| 129 | - $this->value['font-italic'] = false; |
|
| 130 | - $this->value['font-underline'] = false; |
|
| 131 | - $this->value['font-overline'] = false; |
|
| 132 | - $this->value['font-linethrough'] = false; |
|
| 133 | - $this->value['text-transform'] = 'none'; |
|
| 134 | - $this->value['font-size'] = $this->convertToMM('10pt'); |
|
| 135 | - $this->value['text-indent'] = 0; |
|
| 136 | - $this->value['text-align'] = 'left'; |
|
| 137 | - $this->value['vertical-align'] = 'middle'; |
|
| 138 | - $this->value['line-height'] = 'normal'; |
|
| 139 | - |
|
| 140 | - $this->value['position'] = null; |
|
| 141 | - $this->value['x'] = null; |
|
| 142 | - $this->value['y'] = null; |
|
| 143 | - $this->value['width'] = 0; |
|
| 144 | - $this->value['height'] = 0; |
|
| 145 | - $this->value['top'] = null; |
|
| 146 | - $this->value['right'] = null; |
|
| 147 | - $this->value['bottom'] = null; |
|
| 148 | - $this->value['left'] = null; |
|
| 149 | - $this->value['float'] = null; |
|
| 150 | - $this->value['display'] = null; |
|
| 151 | - $this->value['rotate'] = null; |
|
| 152 | - $this->value['overflow'] = 'visible'; |
|
| 153 | - |
|
| 154 | - $this->value['color'] = array(0, 0, 0); |
|
| 155 | - $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 156 | - $this->value['border'] = array(); |
|
| 157 | - $this->value['padding'] = array(); |
|
| 158 | - $this->value['margin'] = array(); |
|
| 159 | - $this->value['margin-auto'] = false; |
|
| 160 | - |
|
| 161 | - $this->value['list-style-type'] = ''; |
|
| 162 | - $this->value['list-style-image'] = ''; |
|
| 163 | - |
|
| 164 | - $this->value['xc'] = null; |
|
| 165 | - $this->value['yc'] = null; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Init the CSS Style without legacy |
|
| 170 | - * |
|
| 171 | - * @param string tag name |
|
| 172 | - * @access public |
|
| 173 | - */ |
|
| 174 | - public function resetStyle($tagName = '') |
|
| 175 | - { |
|
| 176 | - // prepare somme values |
|
| 177 | - $border = $this->readBorder('solid 1px #000000'); |
|
| 178 | - $units = array( |
|
| 179 | - '1px' => $this->convertToMM('1px'), |
|
| 180 | - '5px' => $this->convertToMM('5px'), |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - // prepare the Collapse attribute |
|
| 185 | - $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false; |
|
| 186 | - if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) $collapse = false; |
|
| 187 | - |
|
| 188 | - // set the global css values |
|
| 189 | - $this->value['position'] = null; |
|
| 190 | - $this->value['x'] = null; |
|
| 191 | - $this->value['y'] = null; |
|
| 192 | - $this->value['width'] = 0; |
|
| 193 | - $this->value['height'] = 0; |
|
| 194 | - $this->value['top'] = null; |
|
| 195 | - $this->value['right'] = null; |
|
| 196 | - $this->value['bottom'] = null; |
|
| 197 | - $this->value['left'] = null; |
|
| 198 | - $this->value['float'] = null; |
|
| 199 | - $this->value['display'] = null; |
|
| 200 | - $this->value['rotate'] = null; |
|
| 201 | - $this->value['overflow'] = 'visible'; |
|
| 202 | - $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 203 | - $this->value['border'] = array( |
|
| 204 | - 't' => $this->readBorder('none'), |
|
| 205 | - 'r' => $this->readBorder('none'), |
|
| 206 | - 'b' => $this->readBorder('none'), |
|
| 207 | - 'l' => $this->readBorder('none'), |
|
| 208 | - 'radius' => array( |
|
| 209 | - 'tl' => array(0, 0), |
|
| 210 | - 'tr' => array(0, 0), |
|
| 211 | - 'br' => array(0, 0), |
|
| 212 | - 'bl' => array(0, 0) |
|
| 213 | - ), |
|
| 214 | - 'collapse' => $collapse, |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - // specific values for some tags |
|
| 218 | - if ( ! in_array($tagName, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) { |
|
| 219 | - $this->value['margin'] = array('t'=>0, 'r'=>0, 'b'=>0, 'l'=>0); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (in_array($tagName, array('input', 'select', 'textarea'))) { |
|
| 223 | - $this->value['border']['t'] = null; |
|
| 224 | - $this->value['border']['r'] = null; |
|
| 225 | - $this->value['border']['b'] = null; |
|
| 226 | - $this->value['border']['l'] = null; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($tagName == 'p') { |
|
| 230 | - $this->value['margin']['t'] = null; |
|
| 231 | - $this->value['margin']['b'] = null; |
|
| 232 | - } |
|
| 233 | - if ($tagName == 'blockquote') { |
|
| 234 | - $this->value['margin']['t'] = 3; |
|
| 235 | - $this->value['margin']['r'] = 3; |
|
| 236 | - $this->value['margin']['b'] = 3; |
|
| 237 | - $this->value['margin']['l'] = 6; |
|
| 238 | - } |
|
| 239 | - $this->value['margin-auto'] = false; |
|
| 240 | - |
|
| 241 | - if (in_array($tagName, array('blockquote', 'div', 'fieldset'))) { |
|
| 242 | - $this->value['vertical-align'] = 'top'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if (in_array($tagName, array('fieldset', 'legend'))) { |
|
| 246 | - $this->value['border'] = array( |
|
| 247 | - 't' => $border, |
|
| 248 | - 'r' => $border, |
|
| 249 | - 'b' => $border, |
|
| 250 | - 'l' => $border, |
|
| 251 | - 'radius' => array( |
|
| 252 | - 'tl' => array($units['5px'], $units['5px']), |
|
| 253 | - 'tr' => array($units['5px'], $units['5px']), |
|
| 254 | - 'br' => array($units['5px'], $units['5px']), |
|
| 255 | - 'bl' => array($units['5px'], $units['5px']) |
|
| 256 | - ), |
|
| 257 | - 'collapse' => false, |
|
| 258 | - ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (in_array($tagName, array('ul', 'li'))) { |
|
| 262 | - $this->value['list-style-type'] = ''; |
|
| 263 | - $this->value['list-style-image'] = ''; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if ( ! in_array($tagName, array('tr', 'td'))) { |
|
| 267 | - $this->value['padding'] = array( |
|
| 268 | - 't' => 0, |
|
| 269 | - 'r' => 0, |
|
| 270 | - 'b' => 0, |
|
| 271 | - 'l' => 0 |
|
| 272 | - ); |
|
| 273 | - } else { |
|
| 274 | - $this->value['padding'] = array( |
|
| 275 | - 't' => $units['1px'], |
|
| 276 | - 'r' => $units['1px'], |
|
| 277 | - 'b' => $units['1px'], |
|
| 278 | - 'l' => $units['1px'] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - if ($tagName == 'hr') { |
|
| 283 | - $this->value['border'] = array( |
|
| 284 | - 't' => $border, |
|
| 285 | - 'r' => $border, |
|
| 286 | - 'b' => $border, |
|
| 287 | - 'l' => $border, |
|
| 288 | - 'radius' => array( |
|
| 289 | - 'tl' => array(0, 0), |
|
| 290 | - 'tr' => array(0, 0), |
|
| 291 | - 'br' => array(0, 0), |
|
| 292 | - 'bl' => array(0, 0) |
|
| 293 | - ), |
|
| 294 | - 'collapse' => false, |
|
| 295 | - ); |
|
| 296 | - $this->convertBackground('#FFFFFF', $this->value['background']); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->value['xc'] = null; |
|
| 300 | - $this->value['yc'] = null; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Init the PDF Font |
|
| 305 | - * |
|
| 306 | - * @access public |
|
| 307 | - */ |
|
| 308 | - public function fontSet() |
|
| 309 | - { |
|
| 310 | - $family = strtolower($this->value['font-family']); |
|
| 311 | - |
|
| 312 | - $b = ($this->value['font-bold'] ? 'B' : ''); |
|
| 313 | - $i = ($this->value['font-italic'] ? 'I' : ''); |
|
| 314 | - $u = ($this->value['font-underline'] ? 'U' : ''); |
|
| 315 | - $d = ($this->value['font-linethrough'] ? 'D' : ''); |
|
| 316 | - $o = ($this->value['font-overline'] ? 'O' : ''); |
|
| 317 | - |
|
| 318 | - // font style |
|
| 319 | - $style = $b.$i; |
|
| 320 | - |
|
| 321 | - if ($this->_defaultFont) { |
|
| 322 | - if ($family == 'arial') |
|
| 323 | - $family = 'helvetica'; |
|
| 324 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 325 | - $style = ''; |
|
| 326 | - |
|
| 327 | - $fontkey = $family.$style; |
|
| 328 | - if ( ! $this->_pdf->isLoadedFont($fontkey)) |
|
| 329 | - $family = $this->_defaultFont; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - if ($family == 'arial') |
|
| 333 | - $family = 'helvetica'; |
|
| 334 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 335 | - $style = ''; |
|
| 336 | - |
|
| 337 | - // complete style |
|
| 338 | - $style .= $u.$d.$o; |
|
| 339 | - |
|
| 340 | - // size : mm => pt |
|
| 341 | - $size = $this->value['font-size']; |
|
| 342 | - $size = 72 * $size / 25.4; |
|
| 343 | - |
|
| 344 | - // apply the font |
|
| 345 | - $this->_pdf->SetFont($family, $style, $this->value['mini-size'] * $size); |
|
| 346 | - $this->_pdf->setTextColorArray($this->value['color']); |
|
| 347 | - if ($this->value['background']['color']) { |
|
| 348 | - $this->_pdf->setFillColorArray($this->value['background']['color']); |
|
| 349 | - } else { |
|
| 350 | - $this->_pdf->setFillColor(255); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * add a level in the CSS history |
|
| 356 | - * |
|
| 357 | - * @access public |
|
| 358 | - */ |
|
| 359 | - public function save() |
|
| 360 | - { |
|
| 361 | - array_push($this->table, $this->value); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * remove a level in the CSS history |
|
| 366 | - * |
|
| 367 | - * @access public |
|
| 368 | - */ |
|
| 369 | - public function load() |
|
| 370 | - { |
|
| 371 | - if (count($this->table)) { |
|
| 372 | - $this->value = array_pop($this->table); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * restore the Y positiony (used after a span) |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - */ |
|
| 381 | - public function restorePosition() |
|
| 382 | - { |
|
| 383 | - if ($this->value['y'] == $this->_pdf->getY()) $this->_pdf->setY($this->value['yc'], false); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * set the New position for the current Tag |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - */ |
|
| 391 | - public function setPosition() |
|
| 392 | - { |
|
| 393 | - // get the current position |
|
| 394 | - $currentX = $this->_pdf->getX(); |
|
| 395 | - $currentY = $this->_pdf->getY(); |
|
| 396 | - |
|
| 397 | - // save it |
|
| 398 | - $this->value['xc'] = $currentX; |
|
| 399 | - $this->value['yc'] = $currentY; |
|
| 400 | - |
|
| 401 | - if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') { |
|
| 402 | - if ($this->value['right'] !== null) { |
|
| 403 | - $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; |
|
| 404 | - if ($this->value['margin']['r']) $x -= $this->value['margin']['r']; |
|
| 405 | - } else { |
|
| 406 | - $x = $this->value['left']; |
|
| 407 | - if ($this->value['margin']['l']) $x += $this->value['margin']['l']; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if ($this->value['bottom'] !== null) { |
|
| 411 | - $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; |
|
| 412 | - if ($this->value['margin']['b']) $y -= $this->value['margin']['b']; |
|
| 413 | - } else { |
|
| 414 | - $y = $this->value['top']; |
|
| 415 | - if ($this->value['margin']['t']) $y += $this->value['margin']['t']; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - if ($this->value['position'] == 'relative') { |
|
| 419 | - $this->value['x'] = $currentX + $x; |
|
| 420 | - $this->value['y'] = $currentY + $y; |
|
| 421 | - } else { |
|
| 422 | - $this->value['x'] = $this->_getLastAbsoluteX() + $x; |
|
| 423 | - $this->value['y'] = $this->_getLastAbsoluteY() + $y; |
|
| 424 | - } |
|
| 425 | - } else { |
|
| 426 | - $this->value['x'] = $currentX; |
|
| 427 | - $this->value['y'] = $currentY; |
|
| 428 | - if ($this->value['margin']['l']) $this->value['x'] += $this->value['margin']['l']; |
|
| 429 | - if ($this->value['margin']['t']) $this->value['y'] += $this->value['margin']['t']; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // save the new position |
|
| 433 | - $this->_pdf->setXY($this->value['x'], $this->value['y']); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Analise the CSS style to convert it into Form style |
|
| 438 | - * |
|
| 439 | - * @access public |
|
| 440 | - * @param array styles |
|
| 441 | - */ |
|
| 442 | - public function getFormStyle() |
|
| 443 | - { |
|
| 444 | - $prop = array(); |
|
| 445 | - |
|
| 446 | - $prop['alignment'] = $this->value['text-align']; |
|
| 447 | - |
|
| 448 | - if (isset($this->value['background']['color']) && is_array($this->value['background']['color'])) { |
|
| 449 | - $prop['fillColor'] = $this->value['background']['color']; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - if (isset($this->value['border']['t']['color'])) { |
|
| 453 | - $prop['strokeColor'] = $this->value['border']['t']['color']; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if (isset($this->value['border']['t']['width'])) { |
|
| 457 | - $prop['lineWidth'] = $this->value['border']['t']['width']; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - if (isset($this->value['border']['t']['type'])) { |
|
| 461 | - $prop['borderStyle'] = $this->value['border']['t']['type']; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - if ( ! empty($this->value['color'])) { |
|
| 465 | - $prop['textColor'] = $this->value['color']; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - if ( ! empty($this->value['font-size'])) { |
|
| 469 | - $prop['textSize'] = $this->value['font-size']; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - return $prop; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Analise the CSS style to convert it into SVG style |
|
| 477 | - * |
|
| 478 | - * @access public |
|
| 479 | - * @param string tag name |
|
| 480 | - * @param array styles |
|
| 481 | - * @param string $tagName |
|
| 482 | - */ |
|
| 483 | - public function getSvgStyle($tagName, &$param) |
|
| 484 | - { |
|
| 485 | - // prepare |
|
| 486 | - $tagName = strtolower($tagName); |
|
| 487 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 489 | - |
|
| 490 | - // read the class attribute |
|
| 491 | - $class = array(); |
|
| 492 | - $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 493 | - $tmp = explode(' ', $tmp); |
|
| 494 | - foreach ($tmp as $k => $v) { |
|
| 495 | - $v = trim($v); |
|
| 496 | - if ($v) { |
|
| 497 | - $class[] = $v; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // identify the tag, and the direct styles |
|
| 502 | - $this->value['id_tag'] = $tagName; |
|
| 503 | - $this->value['id_name'] = $name; |
|
| 504 | - $this->value['id_id'] = $id; |
|
| 505 | - $this->value['id_class'] = $class; |
|
| 506 | - $this->value['id_lst'] = array(); |
|
| 507 | - $this->value['id_lst'][] = '*'; |
|
| 508 | - $this->value['id_lst'][] = $tagName; |
|
| 509 | - if ( ! isset($this->value['svg'])) { |
|
| 510 | - $this->value['svg'] = array( |
|
| 511 | - 'stroke' => null, |
|
| 512 | - 'stroke-width' => $this->convertToMM('1pt'), |
|
| 513 | - 'fill' => null, |
|
| 514 | - 'fill-opacity' => null, |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (count($class)) { |
|
| 519 | - foreach ($class as $v) { |
|
| 520 | - $this->value['id_lst'][] = '*.'.$v; |
|
| 521 | - $this->value['id_lst'][] = '.'.$v; |
|
| 522 | - $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - if ($id) { |
|
| 526 | - $this->value['id_lst'][] = '*#'.$id; |
|
| 527 | - $this->value['id_lst'][] = '#'.$id; |
|
| 528 | - $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - // CSS style |
|
| 532 | - $styles = $this->_getFromCSS(); |
|
| 533 | - |
|
| 534 | - // adding the style from the tag |
|
| 535 | - $styles = array_merge($styles, $param['style']); |
|
| 536 | - |
|
| 537 | - if (isset($styles['stroke'])) $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 538 | - if (isset($styles['stroke-width'])) $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 539 | - if (isset($styles['fill'])) $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 540 | - if (isset($styles['fill-opacity'])) $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 541 | - |
|
| 542 | - return $this->value['svg']; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * analyse the css properties from the HTML parsing |
|
| 547 | - * |
|
| 548 | - * @access public |
|
| 549 | - * @param string $tagName |
|
| 550 | - * @param array $param |
|
| 551 | - * @param array $legacy |
|
| 552 | - */ |
|
| 553 | - public function analyse($tagName, &$param, $legacy = null) |
|
| 554 | - { |
|
| 555 | - // prepare the informations |
|
| 556 | - $tagName = strtolower($tagName); |
|
| 557 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 559 | - |
|
| 560 | - // get the class names to use |
|
| 561 | - $class = array(); |
|
| 562 | - $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 563 | - $tmp = explode(' ', $tmp); |
|
| 564 | - foreach ($tmp as $k => $v) { |
|
| 565 | - $v = trim($v); |
|
| 566 | - if ($v) { |
|
| 567 | - $class[] = $v; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // prepare the values, and the list of css tags to identify |
|
| 572 | - $this->value['id_tag'] = $tagName; |
|
| 573 | - $this->value['id_name'] = $name; |
|
| 574 | - $this->value['id_id'] = $id; |
|
| 575 | - $this->value['id_class'] = $class; |
|
| 576 | - $this->value['id_lst'] = array(); |
|
| 577 | - $this->value['id_lst'][] = '*'; |
|
| 578 | - $this->value['id_lst'][] = $tagName; |
|
| 579 | - if (count($class)) { |
|
| 580 | - foreach ($class as $v) { |
|
| 581 | - $this->value['id_lst'][] = '*.'.$v; |
|
| 582 | - $this->value['id_lst'][] = '.'.$v; |
|
| 583 | - $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if ($id) { |
|
| 587 | - $this->value['id_lst'][] = '*#'.$id; |
|
| 588 | - $this->value['id_lst'][] = '#'.$id; |
|
| 589 | - $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // get the css styles from class |
|
| 593 | - $styles = $this->_getFromCSS(); |
|
| 594 | - |
|
| 595 | - // merge with the css styles from tag |
|
| 596 | - $styles = array_merge($styles, $param['style']); |
|
| 597 | - if (isset($param['allwidth']) && ! isset($styles['width'])) $styles['width'] = '100%'; |
|
| 598 | - |
|
| 599 | - // reset some styles, depending on the tag name |
|
| 600 | - $this->resetStyle($tagName); |
|
| 601 | - |
|
| 602 | - // add the legacy values |
|
| 603 | - if ($legacy) { |
|
| 604 | - foreach ($legacy as $legacyName => $legacyValue) { |
|
| 605 | - if (is_array($legacyValue)) { |
|
| 606 | - foreach ($legacyValue as $legacy2Name => $legacy2Value) |
|
| 607 | - $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 608 | - } else { |
|
| 609 | - $this->value[$legacyName] = $legacyValue; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // some flags |
|
| 615 | - $correctWidth = false; |
|
| 616 | - $noWidth = true; |
|
| 617 | - |
|
| 618 | - // read all the css styles |
|
| 619 | - foreach ($styles as $nom => $val) { |
|
| 620 | - switch ($nom) |
|
| 621 | - { |
|
| 622 | - case 'font-family': |
|
| 623 | - $val = explode(',', $val); |
|
| 624 | - $val = trim($val[0]); |
|
| 625 | - if ($val) { |
|
| 626 | - $this->value['font-family'] = $val; |
|
| 627 | - } |
|
| 628 | - break; |
|
| 629 | - |
|
| 630 | - case 'font-weight': |
|
| 631 | - $this->value['font-bold'] = ($val == 'bold'); |
|
| 632 | - break; |
|
| 633 | - |
|
| 634 | - case 'font-style': |
|
| 635 | - $this->value['font-italic'] = ($val == 'italic'); |
|
| 636 | - break; |
|
| 637 | - |
|
| 638 | - case 'text-decoration': |
|
| 639 | - $val = explode(' ', $val); |
|
| 640 | - $this->value['font-underline'] = (in_array('underline', $val)); |
|
| 641 | - $this->value['font-overline'] = (in_array('overline', $val)); |
|
| 642 | - $this->value['font-linethrough'] = (in_array('line-through', $val)); |
|
| 643 | - break; |
|
| 644 | - |
|
| 645 | - case 'text-indent': |
|
| 646 | - $this->value['text-indent'] = $this->convertToMM($val); |
|
| 647 | - break; |
|
| 648 | - |
|
| 649 | - case 'text-transform': |
|
| 650 | - if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) $val = 'none'; |
|
| 651 | - $this->value['text-transform'] = $val; |
|
| 652 | - break; |
|
| 653 | - |
|
| 654 | - case 'font-size': |
|
| 655 | - $val = $this->convertToMM($val, $this->value['font-size']); |
|
| 656 | - if ($val) $this->value['font-size'] = $val; |
|
| 657 | - break; |
|
| 658 | - |
|
| 659 | - case 'color': |
|
| 660 | - $res = null; |
|
| 661 | - $this->value['color'] = $this->convertToColor($val, $res); |
|
| 662 | - if ($tagName == 'hr') { |
|
| 663 | - $this->value['border']['l']['color'] = $this->value['color']; |
|
| 664 | - $this->value['border']['t']['color'] = $this->value['color']; |
|
| 665 | - $this->value['border']['r']['color'] = $this->value['color']; |
|
| 666 | - $this->value['border']['b']['color'] = $this->value['color']; |
|
| 667 | - } |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'text-align': |
|
| 671 | - $val = strtolower($val); |
|
| 672 | - if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) $val = 'left'; |
|
| 673 | - $this->value['text-align'] = $val; |
|
| 674 | - break; |
|
| 675 | - |
|
| 676 | - case 'vertical-align': |
|
| 677 | - $this->value['vertical-align'] = $val; |
|
| 678 | - break; |
|
| 679 | - |
|
| 680 | - case 'width': |
|
| 681 | - $this->value['width'] = $this->convertToMM($val, $this->getLastWidth()); |
|
| 682 | - if ($this->value['width'] && substr($val, -1) == '%') $correctWidth = true; |
|
| 683 | - $noWidth = false; |
|
| 684 | - break; |
|
| 685 | - |
|
| 686 | - case 'height': |
|
| 687 | - $this->value['height'] = $this->convertToMM($val, $this->getLastHeight()); |
|
| 688 | - break; |
|
| 689 | - |
|
| 690 | - case 'line-height': |
|
| 691 | - if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val * 100).'%'; |
|
| 692 | - $this->value['line-height'] = $val; |
|
| 693 | - break; |
|
| 694 | - |
|
| 695 | - case 'rotate': |
|
| 696 | - if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) $val = null; |
|
| 697 | - if ($val < 0) $val += 360; |
|
| 698 | - $this->value['rotate'] = $val; |
|
| 699 | - break; |
|
| 700 | - |
|
| 701 | - case 'overflow': |
|
| 702 | - if ( ! in_array($val, array('visible', 'hidden'))) $val = 'visible'; |
|
| 703 | - $this->value['overflow'] = $val; |
|
| 704 | - break; |
|
| 705 | - |
|
| 706 | - case 'padding': |
|
| 707 | - $val = explode(' ', $val); |
|
| 708 | - foreach ($val as $k => $v) { |
|
| 709 | - $v = trim($v); |
|
| 710 | - if ($v != '') { |
|
| 711 | - $val[$k] = $v; |
|
| 712 | - } else { |
|
| 713 | - unset($val[$k]); |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - $val = array_values($val); |
|
| 717 | - $this->_duplicateBorder($val); |
|
| 718 | - $this->value['padding']['t'] = $this->convertToMM($val[0], 0); |
|
| 719 | - $this->value['padding']['r'] = $this->convertToMM($val[1], 0); |
|
| 720 | - $this->value['padding']['b'] = $this->convertToMM($val[2], 0); |
|
| 721 | - $this->value['padding']['l'] = $this->convertToMM($val[3], 0); |
|
| 722 | - break; |
|
| 723 | - |
|
| 724 | - case 'padding-top': |
|
| 725 | - $this->value['padding']['t'] = $this->convertToMM($val, 0); |
|
| 726 | - break; |
|
| 727 | - |
|
| 728 | - case 'padding-right': |
|
| 729 | - $this->value['padding']['r'] = $this->convertToMM($val, 0); |
|
| 730 | - break; |
|
| 731 | - |
|
| 732 | - case 'padding-bottom': |
|
| 733 | - $this->value['padding']['b'] = $this->convertToMM($val, 0); |
|
| 734 | - break; |
|
| 735 | - |
|
| 736 | - case 'padding-left': |
|
| 737 | - $this->value['padding']['l'] = $this->convertToMM($val, 0); |
|
| 738 | - break; |
|
| 739 | - |
|
| 740 | - case 'margin': |
|
| 741 | - if ($val == 'auto') { |
|
| 742 | - $this->value['margin-auto'] = true; |
|
| 743 | - break; |
|
| 744 | - } |
|
| 745 | - $val = explode(' ', $val); |
|
| 746 | - foreach ($val as $k => $v) { |
|
| 747 | - $v = trim($v); |
|
| 748 | - if ($v != '') { |
|
| 749 | - $val[$k] = $v; |
|
| 750 | - } else { |
|
| 751 | - unset($val[$k]); |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - $val = array_values($val); |
|
| 755 | - $this->_duplicateBorder($val); |
|
| 756 | - $this->value['margin']['t'] = $this->convertToMM($val[0], 0); |
|
| 757 | - $this->value['margin']['r'] = $this->convertToMM($val[1], 0); |
|
| 758 | - $this->value['margin']['b'] = $this->convertToMM($val[2], 0); |
|
| 759 | - $this->value['margin']['l'] = $this->convertToMM($val[3], 0); |
|
| 760 | - break; |
|
| 761 | - |
|
| 762 | - case 'margin-top': |
|
| 763 | - $this->value['margin']['t'] = $this->convertToMM($val, 0); |
|
| 764 | - break; |
|
| 765 | - |
|
| 766 | - case 'margin-right': |
|
| 767 | - $this->value['margin']['r'] = $this->convertToMM($val, 0); |
|
| 768 | - break; |
|
| 769 | - |
|
| 770 | - case 'margin-bottom': |
|
| 771 | - $this->value['margin']['b'] = $this->convertToMM($val, 0); |
|
| 772 | - break; |
|
| 773 | - |
|
| 774 | - case 'margin-left': |
|
| 775 | - $this->value['margin']['l'] = $this->convertToMM($val, 0); |
|
| 776 | - break; |
|
| 777 | - |
|
| 778 | - case 'border': |
|
| 779 | - $val = $this->readBorder($val); |
|
| 780 | - $this->value['border']['t'] = $val; |
|
| 781 | - $this->value['border']['r'] = $val; |
|
| 782 | - $this->value['border']['b'] = $val; |
|
| 783 | - $this->value['border']['l'] = $val; |
|
| 784 | - break; |
|
| 785 | - |
|
| 786 | - case 'border-style': |
|
| 787 | - $val = explode(' ', $val); |
|
| 788 | - foreach ($val as $valK => $valV) { |
|
| 789 | - if ( ! in_array($valV, array('solid', 'dotted', 'dashed'))) { |
|
| 790 | - $val[$valK] = null; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - $this->_duplicateBorder($val); |
|
| 794 | - if ($val[0]) { |
|
| 795 | - $this->value['border']['t']['type'] = $val[0]; |
|
| 796 | - } |
|
| 797 | - if ($val[1]) { |
|
| 798 | - $this->value['border']['r']['type'] = $val[1]; |
|
| 799 | - } |
|
| 800 | - if ($val[2]) { |
|
| 801 | - $this->value['border']['b']['type'] = $val[2]; |
|
| 802 | - } |
|
| 803 | - if ($val[3]) { |
|
| 804 | - $this->value['border']['l']['type'] = $val[3]; |
|
| 805 | - } |
|
| 806 | - break; |
|
| 807 | - |
|
| 808 | - case 'border-top-style': |
|
| 809 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 810 | - $this->value['border']['t']['type'] = $val; |
|
| 811 | - } |
|
| 812 | - break; |
|
| 813 | - |
|
| 814 | - case 'border-right-style': |
|
| 815 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 816 | - $this->value['border']['r']['type'] = $val; |
|
| 817 | - } |
|
| 818 | - break; |
|
| 819 | - |
|
| 820 | - case 'border-bottom-style': |
|
| 821 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 822 | - $this->value['border']['b']['type'] = $val; |
|
| 823 | - } |
|
| 824 | - break; |
|
| 825 | - |
|
| 826 | - case 'border-left-style': |
|
| 827 | - if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 828 | - $this->value['border']['l']['type'] = $val; |
|
| 829 | - } |
|
| 830 | - break; |
|
| 831 | - |
|
| 832 | - case 'border-color': |
|
| 833 | - $res = false; |
|
| 834 | - $val = preg_replace('/,[\s]+/', ',', $val); |
|
| 835 | - $val = explode(' ', $val); |
|
| 836 | - foreach ($val as $valK => $valV) { |
|
| 837 | - $val[$valK] = $this->convertToColor($valV, $res); |
|
| 838 | - if ( ! $res) { |
|
| 839 | - $val[$valK] = null; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - $this->_duplicateBorder($val); |
|
| 843 | - if (is_array($val[0])) { |
|
| 844 | - $this->value['border']['t']['color'] = $val[0]; |
|
| 845 | - } |
|
| 846 | - if (is_array($val[1])) { |
|
| 847 | - $this->value['border']['r']['color'] = $val[1]; |
|
| 848 | - } |
|
| 849 | - if (is_array($val[2])) { |
|
| 850 | - $this->value['border']['b']['color'] = $val[2]; |
|
| 851 | - } |
|
| 852 | - if (is_array($val[3])) { |
|
| 853 | - $this->value['border']['l']['color'] = $val[3]; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - break; |
|
| 857 | - |
|
| 858 | - case 'border-top-color': |
|
| 859 | - $res = false; |
|
| 860 | - $val = $this->convertToColor($val, $res); |
|
| 861 | - if ($res) { |
|
| 862 | - $this->value['border']['t']['color'] = $val; |
|
| 863 | - } |
|
| 864 | - break; |
|
| 865 | - |
|
| 866 | - case 'border-right-color': |
|
| 867 | - $res = false; |
|
| 868 | - $val = $this->convertToColor($val, $res); |
|
| 869 | - if ($res) { |
|
| 870 | - $this->value['border']['r']['color'] = $val; |
|
| 871 | - } |
|
| 872 | - break; |
|
| 873 | - |
|
| 874 | - case 'border-bottom-color': |
|
| 875 | - $res = false; |
|
| 876 | - $val = $this->convertToColor($val, $res); |
|
| 877 | - if ($res) { |
|
| 878 | - $this->value['border']['b']['color'] = $val; |
|
| 879 | - } |
|
| 880 | - break; |
|
| 881 | - |
|
| 882 | - case 'border-left-color': |
|
| 883 | - $res = false; |
|
| 884 | - $val = $this->convertToColor($val, $res); |
|
| 885 | - if ($res) { |
|
| 886 | - $this->value['border']['l']['color'] = $val; |
|
| 887 | - } |
|
| 888 | - break; |
|
| 889 | - |
|
| 890 | - case 'border-width': |
|
| 891 | - $val = explode(' ', $val); |
|
| 892 | - foreach ($val as $valK => $valV) { |
|
| 893 | - $val[$valK] = $this->convertToMM($valV, 0); |
|
| 894 | - } |
|
| 895 | - $this->_duplicateBorder($val); |
|
| 896 | - if ($val[0]) $this->value['border']['t']['width'] = $val[0]; |
|
| 897 | - if ($val[1]) $this->value['border']['r']['width'] = $val[1]; |
|
| 898 | - if ($val[2]) $this->value['border']['b']['width'] = $val[2]; |
|
| 899 | - if ($val[3]) $this->value['border']['l']['width'] = $val[3]; |
|
| 900 | - break; |
|
| 901 | - |
|
| 902 | - case 'border-top-width': |
|
| 903 | - $val = $this->convertToMM($val, 0); |
|
| 904 | - if ($val) $this->value['border']['t']['width'] = $val; |
|
| 905 | - break; |
|
| 906 | - |
|
| 907 | - case 'border-right-width': |
|
| 908 | - $val = $this->convertToMM($val, 0); |
|
| 909 | - if ($val) $this->value['border']['r']['width'] = $val; |
|
| 910 | - break; |
|
| 911 | - |
|
| 912 | - case 'border-bottom-width': |
|
| 913 | - $val = $this->convertToMM($val, 0); |
|
| 914 | - if ($val) $this->value['border']['b']['width'] = $val; |
|
| 915 | - break; |
|
| 916 | - |
|
| 917 | - case 'border-left-width': |
|
| 918 | - $val = $this->convertToMM($val, 0); |
|
| 919 | - if ($val) $this->value['border']['l']['width'] = $val; |
|
| 920 | - break; |
|
| 921 | - |
|
| 922 | - case 'border-collapse': |
|
| 923 | - if ($tagName == 'table') $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 924 | - break; |
|
| 925 | - |
|
| 926 | - case 'border-radius': |
|
| 927 | - $val = explode('/', $val); |
|
| 928 | - if (count($val) > 2) { |
|
| 929 | - break; |
|
| 930 | - } |
|
| 931 | - $valH = $this->convertToRadius(trim($val[0])); |
|
| 932 | - if (count($valH) < 1 || count($valH) > 4) { |
|
| 933 | - break; |
|
| 934 | - } |
|
| 935 | - if ( ! isset($valH[1])) $valH[1] = $valH[0]; |
|
| 936 | - if ( ! isset($valH[2])) $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 937 | - if ( ! isset($valH[3])) $valH[3] = $valH[1]; |
|
| 938 | - if (isset($val[1])) { |
|
| 939 | - $valV = $this->convertToRadius(trim($val[1])); |
|
| 940 | - if (count($valV) < 1 || count($valV) > 4) { |
|
| 941 | - break; |
|
| 942 | - } |
|
| 943 | - if ( ! isset($valV[1])) $valV[1] = $valV[0]; |
|
| 944 | - if ( ! isset($valV[2])) $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 945 | - if ( ! isset($valV[3])) $valV[3] = $valV[1]; |
|
| 946 | - } else { |
|
| 947 | - $valV = $valH; |
|
| 948 | - } |
|
| 949 | - $this->value['border']['radius'] = array( |
|
| 950 | - 'tl' => array($valH[0], $valV[0]), |
|
| 951 | - 'tr' => array($valH[1], $valV[1]), |
|
| 952 | - 'br' => array($valH[2], $valV[2]), |
|
| 953 | - 'bl' => array($valH[3], $valV[3]) |
|
| 954 | - ); |
|
| 955 | - break; |
|
| 956 | - |
|
| 957 | - case 'border-top-left-radius': |
|
| 958 | - $val = $this->convertToRadius($val); |
|
| 959 | - if (count($val) < 1 || count($val) > 2) { |
|
| 960 | - break; |
|
| 961 | - } |
|
| 962 | - $this->value['border']['radius']['tl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 963 | - break; |
|
| 964 | - |
|
| 965 | - case 'border-top-right-radius': |
|
| 966 | - $val = $this->convertToRadius($val); |
|
| 967 | - if (count($val) < 1 || count($val) > 2) { |
|
| 968 | - break; |
|
| 969 | - } |
|
| 970 | - $this->value['border']['radius']['tr'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 971 | - break; |
|
| 972 | - |
|
| 973 | - case 'border-bottom-right-radius': |
|
| 974 | - $val = $this->convertToRadius($val); |
|
| 975 | - if (count($val) < 1 || count($val) > 2) { |
|
| 976 | - break; |
|
| 977 | - } |
|
| 978 | - $this->value['border']['radius']['br'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 979 | - break; |
|
| 980 | - |
|
| 981 | - case 'border-bottom-left-radius': |
|
| 982 | - $val = $this->convertToRadius($val); |
|
| 983 | - if (count($val) < 1 || count($val) > 2) { |
|
| 984 | - break; |
|
| 985 | - } |
|
| 986 | - $this->value['border']['radius']['bl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 987 | - break; |
|
| 988 | - |
|
| 989 | - case 'border-top': |
|
| 990 | - $this->value['border']['t'] = $this->readBorder($val); |
|
| 991 | - break; |
|
| 992 | - |
|
| 993 | - case 'border-right': |
|
| 994 | - $this->value['border']['r'] = $this->readBorder($val); |
|
| 995 | - break; |
|
| 996 | - |
|
| 997 | - case 'border-bottom': |
|
| 998 | - $this->value['border']['b'] = $this->readBorder($val); |
|
| 999 | - break; |
|
| 1000 | - |
|
| 1001 | - case 'border-left': |
|
| 1002 | - $this->value['border']['l'] = $this->readBorder($val); |
|
| 1003 | - break; |
|
| 1004 | - |
|
| 1005 | - case 'background-color': |
|
| 1006 | - $this->value['background']['color'] = $this->convertBackgroundColor($val); |
|
| 1007 | - break; |
|
| 1008 | - |
|
| 1009 | - case 'background-image': |
|
| 1010 | - $this->value['background']['image'] = $this->convertBackgroundImage($val); |
|
| 1011 | - break; |
|
| 1012 | - |
|
| 1013 | - case 'background-position': |
|
| 1014 | - $res = null; |
|
| 1015 | - $this->value['background']['position'] = $this->convertBackgroundPosition($val, $res); |
|
| 1016 | - break; |
|
| 1017 | - |
|
| 1018 | - case 'background-repeat': |
|
| 1019 | - $this->value['background']['repeat'] = $this->convertBackgroundRepeat($val); |
|
| 1020 | - break; |
|
| 1021 | - |
|
| 1022 | - case 'background': |
|
| 1023 | - $this->convertBackground($val, $this->value['background']); |
|
| 1024 | - break; |
|
| 1025 | - |
|
| 1026 | - case 'position': |
|
| 1027 | - if ($val == 'absolute') $this->value['position'] = 'absolute'; |
|
| 1028 | - else if ($val == 'relative') $this->value['position'] = 'relative'; |
|
| 1029 | - else $this->value['position'] = null; |
|
| 1030 | - break; |
|
| 1031 | - |
|
| 1032 | - case 'float': |
|
| 1033 | - if ($val == 'left') $this->value['float'] = 'left'; |
|
| 1034 | - else if ($val == 'right') $this->value['float'] = 'right'; |
|
| 1035 | - else $this->value['float'] = null; |
|
| 1036 | - break; |
|
| 1037 | - |
|
| 1038 | - case 'display': |
|
| 1039 | - if ($val == 'inline') $this->value['display'] = 'inline'; |
|
| 1040 | - else if ($val == 'block') $this->value['display'] = 'block'; |
|
| 1041 | - else if ($val == 'none') $this->value['display'] = 'none'; |
|
| 1042 | - else $this->value['display'] = null; |
|
| 1043 | - break; |
|
| 1044 | - |
|
| 1045 | - case 'top': |
|
| 1046 | - case 'bottom': |
|
| 1047 | - case 'left': |
|
| 1048 | - case 'right': |
|
| 1049 | - $this->value[$nom] = $val; |
|
| 1050 | - break; |
|
| 1051 | - |
|
| 1052 | - case 'list-style': |
|
| 1053 | - case 'list-style-type': |
|
| 1054 | - case 'list-style-image': |
|
| 1055 | - if ($nom == 'list-style') $nom = 'list-style-type'; |
|
| 1056 | - $this->value[$nom] = $val; |
|
| 1057 | - break; |
|
| 1058 | - |
|
| 1059 | - default: |
|
| 1060 | - break; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - $return = true; |
|
| 1065 | - |
|
| 1066 | - // only for P tag |
|
| 1067 | - if ($this->value['margin']['t'] === null) $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1068 | - if ($this->value['margin']['b'] === null) $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1069 | - |
|
| 1070 | - // force the text align to left, if asked by html2pdf |
|
| 1071 | - if ($this->_onlyLeft) $this->value['text-align'] = 'left'; |
|
| 1072 | - |
|
| 1073 | - // correction on the width (quick box) |
|
| 1074 | - if ($noWidth && in_array($tagName, array('div', 'blockquote', 'fieldset')) && $this->value['position'] != 'absolute') { |
|
| 1075 | - $this->value['width'] = $this->getLastWidth(); |
|
| 1076 | - $this->value['width'] -= $this->value['margin']['l'] + $this->value['margin']['r']; |
|
| 1077 | - } else { |
|
| 1078 | - if ($correctWidth) { |
|
| 1079 | - if ( ! in_array($tagName, array('table', 'div', 'blockquote', 'fieldset', 'hr'))) { |
|
| 1080 | - $this->value['width'] -= $this->value['padding']['l'] + $this->value['padding']['r']; |
|
| 1081 | - $this->value['width'] -= $this->value['border']['l']['width'] + $this->value['border']['r']['width']; |
|
| 1082 | - } |
|
| 1083 | - if (in_array($tagName, array('th', 'td'))) { |
|
| 1084 | - $this->value['width'] -= $this->convertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 1085 | - $return = false; |
|
| 1086 | - } |
|
| 1087 | - if ($this->value['width'] < 0) $this->value['width'] = 0; |
|
| 1088 | - } else { |
|
| 1089 | - if ($this->value['width']) { |
|
| 1090 | - if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1091 | - if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1092 | - if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l']; |
|
| 1093 | - if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r']; |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - if ($this->value['height']) { |
|
| 1098 | - if ($this->value['border']['b']['width']) $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1099 | - if ($this->value['border']['t']['width']) $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1100 | - if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b']; |
|
| 1101 | - if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t']; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - if ($this->value['top'] != null) $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1105 | - if ($this->value['bottom'] != null) $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1106 | - if ($this->value['left'] != null) $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1107 | - if ($this->value['right'] != null) $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1108 | - |
|
| 1109 | - if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null; |
|
| 1110 | - if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null; |
|
| 1111 | - |
|
| 1112 | - return $return; |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * get the height of the current line |
|
| 1117 | - * |
|
| 1118 | - * @access public |
|
| 1119 | - * @return float $height in mm |
|
| 1120 | - */ |
|
| 1121 | - public function getLineHeight() |
|
| 1122 | - { |
|
| 1123 | - $val = $this->value['line-height']; |
|
| 1124 | - if ($val == 'normal') $val = '108%'; |
|
| 1125 | - return $this->convertToMM($val, $this->value['font-size']); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - /** |
|
| 1129 | - * get the width of the parent |
|
| 1130 | - * |
|
| 1131 | - * @access public |
|
| 1132 | - * @param boolean $mode true => adding padding and border |
|
| 1133 | - * @return float $width in mm |
|
| 1134 | - */ |
|
| 1135 | - public function getLastWidth($mode = false) |
|
| 1136 | - { |
|
| 1137 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1138 | - if ($this->table[$k]['width']) { |
|
| 1139 | - $w = $this->table[$k]['width']; |
|
| 1140 | - if ($mode) { |
|
| 1141 | - $w += $this->table[$k]['border']['l']['width'] + $this->table[$k]['padding']['l'] + 0.02; |
|
| 1142 | - $w += $this->table[$k]['border']['r']['width'] + $this->table[$k]['padding']['r'] + 0.02; |
|
| 1143 | - } |
|
| 1144 | - return $w; |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - return $this->_pdf->getW() - $this->_pdf->getlMargin() - $this->_pdf->getrMargin(); |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * get the height of the parent |
|
| 1152 | - * |
|
| 1153 | - * @access public |
|
| 1154 | - * @param boolean $mode true => adding padding and border |
|
| 1155 | - * @return float $height in mm |
|
| 1156 | - */ |
|
| 1157 | - public function getLastHeight($mode = false) |
|
| 1158 | - { |
|
| 1159 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1160 | - if ($this->table[$k]['height']) { |
|
| 1161 | - $h = $this->table[$k]['height']; |
|
| 1162 | - if ($mode) { |
|
| 1163 | - $h += $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; |
|
| 1164 | - $h += $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; |
|
| 1165 | - } |
|
| 1166 | - return $h; |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - return $this->_pdf->getH() - $this->_pdf->gettMargin() - $this->_pdf->getbMargin(); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * get the value of the float property |
|
| 1174 | - * |
|
| 1175 | - * @access public |
|
| 1176 | - * @return $float left/right |
|
| 1177 | - */ |
|
| 1178 | - public function getFloat() |
|
| 1179 | - { |
|
| 1180 | - if ($this->value['float'] == 'left') return 'left'; |
|
| 1181 | - if ($this->value['float'] == 'right') return 'right'; |
|
| 1182 | - return null; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * get the last value for a specific key |
|
| 1187 | - * |
|
| 1188 | - * @access public |
|
| 1189 | - * @param string $key |
|
| 1190 | - * @return mixed |
|
| 1191 | - */ |
|
| 1192 | - public function getLastValue($key) |
|
| 1193 | - { |
|
| 1194 | - $nb = count($this->table); |
|
| 1195 | - if ($nb > 0) { |
|
| 1196 | - return $this->table[$nb - 1][$key]; |
|
| 1197 | - } else { |
|
| 1198 | - return null; |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * get the last absolute X |
|
| 1204 | - * |
|
| 1205 | - * @access protected |
|
| 1206 | - * @return float $x |
|
| 1207 | - */ |
|
| 1208 | - protected function _getLastAbsoluteX() |
|
| 1209 | - { |
|
| 1210 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1211 | - if ($this->table[$k]['x'] && $this->table[$k]['position']) return $this->table[$k]['x']; |
|
| 1212 | - } |
|
| 1213 | - return $this->_pdf->getlMargin(); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * get the last absolute Y |
|
| 1218 | - * |
|
| 1219 | - * @access protected |
|
| 1220 | - * @return float $y |
|
| 1221 | - */ |
|
| 1222 | - protected function _getLastAbsoluteY() |
|
| 1223 | - { |
|
| 1224 | - for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1225 | - if ($this->table[$k]['y'] && $this->table[$k]['position']) return $this->table[$k]['y']; |
|
| 1226 | - } |
|
| 1227 | - return $this->_pdf->gettMargin(); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * get the CSS properties of the current tag |
|
| 1232 | - * |
|
| 1233 | - * @access protected |
|
| 1234 | - * @return array $styles |
|
| 1235 | - */ |
|
| 1236 | - protected function _getFromCSS() |
|
| 1237 | - { |
|
| 1238 | - // styles to apply |
|
| 1239 | - $styles = array(); |
|
| 1240 | - |
|
| 1241 | - // list of the selectors to get in the CSS files |
|
| 1242 | - $getit = array(); |
|
| 1243 | - |
|
| 1244 | - // get the list of the selectors of each tags |
|
| 1245 | - $lst = array(); |
|
| 1246 | - $lst[] = $this->value['id_lst']; |
|
| 1247 | - for ($i = count($this->table) - 1; $i >= 0; $i--) { |
|
| 1248 | - $lst[] = $this->table[$i]['id_lst']; |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - // foreach selectors in the CSS files, verify if it match with the list of selectors |
|
| 1252 | - foreach ($this->cssKeys as $key => $num) { |
|
| 1253 | - if ($this->_getReccursiveStyle($key, $lst)) { |
|
| 1254 | - $getit[$key] = $num; |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - // if we have selectors |
|
| 1259 | - if (count($getit)) { |
|
| 1260 | - // get them, but in the definition order, because of priority |
|
| 1261 | - asort($getit); |
|
| 1262 | - foreach ($getit as $key => $val) { |
|
| 1263 | - $styles = array_merge($styles, $this->css[$key]); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - return $styles; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * identify if the selector $key match with the list of tag selectors |
|
| 1272 | - * |
|
| 1273 | - * @access protected |
|
| 1274 | - * @param string $key CSS selector to analyse |
|
| 1275 | - * @param array $lst list of the selectors of each tags |
|
| 1276 | - * @param string $next next step of parsing the selector |
|
| 1277 | - * @return boolean |
|
| 1278 | - */ |
|
| 1279 | - protected function _getReccursiveStyle($key, $lst, $next = null) |
|
| 1280 | - { |
|
| 1281 | - // if next step |
|
| 1282 | - if ($next !== null) { |
|
| 1283 | - // we remove this step |
|
| 1284 | - if ($next) { |
|
| 1285 | - $key = trim(substr($key, 0, -strlen($next))); |
|
| 1286 | - } |
|
| 1287 | - array_shift($lst); |
|
| 1288 | - |
|
| 1289 | - // if no more step to identify => return false |
|
| 1290 | - if ( ! count($lst)) { |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - // for each selector of the current step |
|
| 1296 | - foreach ($lst[0] as $name) { |
|
| 1297 | - // if selector = key => ok |
|
| 1298 | - if ($key == $name) { |
|
| 1299 | - return true; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // if the end of the key = the selector and the next step is ok => ok |
|
| 1303 | - if (substr($key, -strlen(' '.$name)) == ' '.$name && $this->_getReccursiveStyle($key, $lst, $name)) { |
|
| 1304 | - return true; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - // if we are not in the first step, we analyse the sub steps (the pareng tag of the current tag) |
|
| 1309 | - if ($next !== null && $this->_getReccursiveStyle($key, $lst, '')) { |
|
| 1310 | - return true; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - // no corresponding found |
|
| 1314 | - return false; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * Analyse a border |
|
| 1319 | - * |
|
| 1320 | - * @access public |
|
| 1321 | - * @param string $css css border properties |
|
| 1322 | - * @return array border properties |
|
| 1323 | - */ |
|
| 1324 | - public function readBorder($css) |
|
| 1325 | - { |
|
| 1326 | - // border none |
|
| 1327 | - $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 1328 | - |
|
| 1329 | - // default value |
|
| 1330 | - $type = 'solid'; |
|
| 1331 | - $width = $this->convertToMM('1pt'); |
|
| 1332 | - $color = array(0, 0, 0); |
|
| 1333 | - |
|
| 1334 | - // clean up the values |
|
| 1335 | - $css = explode(' ', $css); |
|
| 1336 | - foreach ($css as $k => $v) { |
|
| 1337 | - $v = trim($v); |
|
| 1338 | - if ($v) { |
|
| 1339 | - $css[$k] = $v; |
|
| 1340 | - } else { |
|
| 1341 | - unset($css[$k]); |
|
| 1342 | - } |
|
| 1343 | - } |
|
| 1344 | - $css = array_values($css); |
|
| 1345 | - |
|
| 1346 | - // read the values |
|
| 1347 | - $res = null; |
|
| 1348 | - foreach ($css as $value) { |
|
| 1349 | - |
|
| 1350 | - // if no border => return none |
|
| 1351 | - if ($value == 'none' || $value == 'hidden') { |
|
| 1352 | - return $none; |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - // try to convert the value as a distance |
|
| 1356 | - $tmp = $this->convertToMM($value); |
|
| 1357 | - |
|
| 1358 | - // if the convert is ok => it is a width |
|
| 1359 | - if ($tmp !== null) { |
|
| 1360 | - $width = $tmp; |
|
| 1361 | - // else, it could be the type |
|
| 1362 | - } else if (in_array($value, array('solid', 'dotted', 'dashed', 'double'))) { |
|
| 1363 | - $type = $value; |
|
| 1364 | - // else, it could be the color |
|
| 1365 | - } else { |
|
| 1366 | - $tmp = $this->convertToColor($value, $res); |
|
| 1367 | - if ($res) $color = $tmp; |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - // if no witdh => return none |
|
| 1372 | - if ( ! $width) return $none; |
|
| 1373 | - |
|
| 1374 | - // return the border properties |
|
| 1375 | - return array('type' => $type, 'width' => $width, 'color' => $color); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * duplicate the borders if needed |
|
| 1380 | - * |
|
| 1381 | - * @access protected |
|
| 1382 | - * @param &array $val |
|
| 1383 | - */ |
|
| 1384 | - protected function _duplicateBorder(&$val) |
|
| 1385 | - { |
|
| 1386 | - // 1 value => L => RTB |
|
| 1387 | - if (count($val) == 1) { |
|
| 1388 | - $val[1] = $val[0]; |
|
| 1389 | - $val[2] = $val[0]; |
|
| 1390 | - $val[3] = $val[0]; |
|
| 1391 | - // 2 values => L => R & T => B |
|
| 1392 | - } else if (count($val) == 2) { |
|
| 1393 | - $val[2] = $val[0]; |
|
| 1394 | - $val[3] = $val[1]; |
|
| 1395 | - // 3 values => T => B |
|
| 1396 | - } else if (count($val) == 3) { |
|
| 1397 | - $val[3] = $val[1]; |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * Analyse a background |
|
| 1403 | - * |
|
| 1404 | - * @access public |
|
| 1405 | - * @param string $css css background properties |
|
| 1406 | - * @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties) |
|
| 1407 | - */ |
|
| 1408 | - public function convertBackground($css, &$value) |
|
| 1409 | - { |
|
| 1410 | - // is there a image ? |
|
| 1411 | - $text = '/url\(([^)]*)\)/isU'; |
|
| 1412 | - if (preg_match($text, $css, $match)) { |
|
| 1413 | - // get the image |
|
| 1414 | - $value['image'] = $this->convertBackgroundImage($match[0]); |
|
| 1415 | - |
|
| 1416 | - // remove if from the css properties |
|
| 1417 | - $css = preg_replace($text, '', $css); |
|
| 1418 | - $css = preg_replace('/[\s]+/', ' ', $css); |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - // protect some spaces |
|
| 1422 | - $css = preg_replace('/,[\s]+/', ',', $css); |
|
| 1423 | - |
|
| 1424 | - // explode the values |
|
| 1425 | - $css = explode(' ', $css); |
|
| 1426 | - |
|
| 1427 | - // background position to parse |
|
| 1428 | - $pos = ''; |
|
| 1429 | - |
|
| 1430 | - // foreach value |
|
| 1431 | - foreach ($css as $val) { |
|
| 1432 | - // try to parse the value as a color |
|
| 1433 | - $ok = false; |
|
| 1434 | - $color = $this->convertToColor($val, $ok); |
|
| 1435 | - |
|
| 1436 | - // if ok => it is a color |
|
| 1437 | - if ($ok) { |
|
| 1438 | - $value['color'] = $color; |
|
| 1439 | - // else if transparent => no coloàr |
|
| 1440 | - } else if ($val == 'transparent') { |
|
| 1441 | - $value['color'] = null; |
|
| 1442 | - // else |
|
| 1443 | - } else { |
|
| 1444 | - // try to parse the value as a repeat |
|
| 1445 | - $repeat = $this->convertBackgroundRepeat($val); |
|
| 1446 | - |
|
| 1447 | - // if ok => it is repeat |
|
| 1448 | - if ($repeat) { |
|
| 1449 | - $value['repeat'] = $repeat; |
|
| 1450 | - // else => it could only be a position |
|
| 1451 | - } else { |
|
| 1452 | - $pos .= ($pos ? ' ' : '').$val; |
|
| 1453 | - } |
|
| 1454 | - } |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - // if we have a position to parse |
|
| 1458 | - if ($pos) { |
|
| 1459 | - // try to read it |
|
| 1460 | - $pos = $this->convertBackgroundPosition($pos, $ok); |
|
| 1461 | - if ($ok) { |
|
| 1462 | - $value['position'] = $pos; |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * parse a background color |
|
| 1469 | - * |
|
| 1470 | - * @access public |
|
| 1471 | - * @param string $css |
|
| 1472 | - * @return string $value |
|
| 1473 | - */ |
|
| 1474 | - public function convertBackgroundColor($css) |
|
| 1475 | - { |
|
| 1476 | - $res = null; |
|
| 1477 | - if ($css == 'transparent') return null; |
|
| 1478 | - else return $this->convertToColor($css, $res); |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * parse a background image |
|
| 1483 | - * |
|
| 1484 | - * @access public |
|
| 1485 | - * @param string $css |
|
| 1486 | - * @return string $value |
|
| 1487 | - */ |
|
| 1488 | - public function convertBackgroundImage($css) |
|
| 1489 | - { |
|
| 1490 | - if ($css == 'none') |
|
| 1491 | - return null; |
|
| 1492 | - else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) |
|
| 1493 | - return $match[1]; |
|
| 1494 | - else |
|
| 1495 | - return null; |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * parse a background position |
|
| 1500 | - * |
|
| 1501 | - * @access public |
|
| 1502 | - * @param string $css |
|
| 1503 | - * @param &boolean $res flag if conver is ok or not |
|
| 1504 | - * @return array ($x, $y) |
|
| 1505 | - */ |
|
| 1506 | - public function convertBackgroundPosition($css, &$res) |
|
| 1507 | - { |
|
| 1508 | - // init the res |
|
| 1509 | - $res = false; |
|
| 1510 | - |
|
| 1511 | - // explode the value |
|
| 1512 | - $css = explode(' ', $css); |
|
| 1513 | - |
|
| 1514 | - // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 |
|
| 1515 | - if (count($css) < 2) { |
|
| 1516 | - if ( ! $css[0]) return null; |
|
| 1517 | - $css[1] = 'center'; |
|
| 1518 | - } |
|
| 1519 | - if (count($css) > 2) return null; |
|
| 1520 | - |
|
| 1521 | - // prepare the values |
|
| 1522 | - $x = 0; |
|
| 1523 | - $y = 0; |
|
| 1524 | - $res = true; |
|
| 1525 | - |
|
| 1526 | - // convert the first value |
|
| 1527 | - if ($css[0] == 'left') $x = '0%'; |
|
| 1528 | - else if ($css[0] == 'center') $x = '50%'; |
|
| 1529 | - else if ($css[0] == 'right') $x = '100%'; |
|
| 1530 | - else if ($css[0] == 'top') $y = '0%'; |
|
| 1531 | - else if ($css[0] == 'bottom') $y = '100%'; |
|
| 1532 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) $x = $css[0]; |
|
| 1533 | - else if ($this->convertToMM($css[0])) $x = $this->convertToMM($css[0]); |
|
| 1534 | - else $res = false; |
|
| 1535 | - |
|
| 1536 | - // convert the second value |
|
| 1537 | - if ($css[1] == 'left') $x = '0%'; |
|
| 1538 | - else if ($css[1] == 'right') $x = '100%'; |
|
| 1539 | - else if ($css[1] == 'top') $y = '0%'; |
|
| 1540 | - else if ($css[1] == 'center') $y = '50%'; |
|
| 1541 | - else if ($css[1] == 'bottom') $y = '100%'; |
|
| 1542 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) $y = $css[1]; |
|
| 1543 | - else if ($this->convertToMM($css[1])) $y = $this->convertToMM($css[1]); |
|
| 1544 | - else $res = false; |
|
| 1545 | - |
|
| 1546 | - // return the values |
|
| 1547 | - return array($x, $y); |
|
| 1548 | - } |
|
| 1549 | - |
|
| 1550 | - /** |
|
| 1551 | - * parse a background repeat |
|
| 1552 | - * |
|
| 1553 | - * @access public |
|
| 1554 | - * @param string $css |
|
| 1555 | - * @return string $value |
|
| 1556 | - */ |
|
| 1557 | - public function convertBackgroundRepeat($css) |
|
| 1558 | - { |
|
| 1559 | - switch ($css) |
|
| 1560 | - { |
|
| 1561 | - case 'repeat': |
|
| 1562 | - return array(true, true); |
|
| 1563 | - case 'repeat-x': |
|
| 1564 | - return array(true, false); |
|
| 1565 | - case 'repeat-y': |
|
| 1566 | - return array(false, true); |
|
| 1567 | - case 'no-repeat': |
|
| 1568 | - return array(false, false); |
|
| 1569 | - } |
|
| 1570 | - return null; |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * convert a distance to mm |
|
| 1575 | - * |
|
| 1576 | - * @access public |
|
| 1577 | - * @param string $css distance to convert |
|
| 1578 | - * @param float $old parent distance |
|
| 1579 | - * @return float $value |
|
| 1580 | - */ |
|
| 1581 | - public function convertToMM($css, $old = 0.) |
|
| 1582 | - { |
|
| 1583 | - $css = trim($css); |
|
| 1584 | - if (preg_match('/^[0-9\.\-]+$/isU', $css)) $css .= 'px'; |
|
| 1585 | - if (preg_match('/^[0-9\.\-]+px$/isU', $css)) $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1586 | - else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1587 | - else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) $css = 25.4 * str_replace('in', '', $css); |
|
| 1588 | - else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) $css = 1. * str_replace('mm', '', $css); |
|
| 1589 | - else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1590 | - else $css = null; |
|
| 1591 | - |
|
| 1592 | - return $css; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * convert a css radius |
|
| 1597 | - * |
|
| 1598 | - * @access public |
|
| 1599 | - * @param string $css |
|
| 1600 | - * @return float $value |
|
| 1601 | - */ |
|
| 1602 | - public function convertToRadius($css) |
|
| 1603 | - { |
|
| 1604 | - // explode the value |
|
| 1605 | - $css = explode(' ', $css); |
|
| 1606 | - |
|
| 1607 | - foreach ($css as $k => $v) { |
|
| 1608 | - $v = trim($v); |
|
| 1609 | - if ($v) { |
|
| 1610 | - $v = $this->convertToMM($v, 0); |
|
| 1611 | - if ($v !== null) { |
|
| 1612 | - $css[$k] = $v; |
|
| 1613 | - } else { |
|
| 1614 | - unset($css[$k]); |
|
| 1615 | - } |
|
| 1616 | - } else { |
|
| 1617 | - unset($css[$k]); |
|
| 1618 | - } |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - return array_values($css); |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - /** |
|
| 1625 | - * convert a css color |
|
| 1626 | - * |
|
| 1627 | - * @access public |
|
| 1628 | - * @param string $css |
|
| 1629 | - * @param &boolean $res |
|
| 1630 | - * @return array (r,g, b) |
|
| 1631 | - */ |
|
| 1632 | - public function convertToColor($css, &$res) |
|
| 1633 | - { |
|
| 1634 | - // prepare the value |
|
| 1635 | - $css = trim($css); |
|
| 1636 | - $res = true; |
|
| 1637 | - |
|
| 1638 | - // if transparent => return null |
|
| 1639 | - if (strtolower($css) == 'transparent') return array(null, null, null); |
|
| 1640 | - |
|
| 1641 | - // HTML color |
|
| 1642 | - if (isset($this->_htmlColor[strtolower($css)])) { |
|
| 1643 | - $css = $this->_htmlColor[strtolower($css)]; |
|
| 1644 | - $r = floatVal(hexdec(substr($css, 0, 2))); |
|
| 1645 | - $v = floatVal(hexdec(substr($css, 2, 2))); |
|
| 1646 | - $b = floatVal(hexdec(substr($css, 4, 2))); |
|
| 1647 | - return array($r, $v, $b); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - // like #FFFFFF |
|
| 1651 | - if (preg_match('/^#[0-9A-Fa-f]{6}$/isU', $css)) { |
|
| 1652 | - $r = floatVal(hexdec(substr($css, 1, 2))); |
|
| 1653 | - $v = floatVal(hexdec(substr($css, 3, 2))); |
|
| 1654 | - $b = floatVal(hexdec(substr($css, 5, 2))); |
|
| 1655 | - return array($r, $v, $b); |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - // like #FFF |
|
| 1659 | - if (preg_match('/^#[0-9A-F]{3}$/isU', $css)) { |
|
| 1660 | - $r = floatVal(hexdec(substr($css, 1, 1).substr($css, 1, 1))); |
|
| 1661 | - $v = floatVal(hexdec(substr($css, 2, 1).substr($css, 2, 1))); |
|
| 1662 | - $b = floatVal(hexdec(substr($css, 3, 1).substr($css, 3, 1))); |
|
| 1663 | - return array($r, $v, $b); |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - // like rgb(100, 100, 100) |
|
| 1667 | - if (preg_match('/rgb\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1668 | - $r = $this->_convertSubColor($match[1]); |
|
| 1669 | - $v = $this->_convertSubColor($match[2]); |
|
| 1670 | - $b = $this->_convertSubColor($match[3]); |
|
| 1671 | - return array($r * 255., $v * 255., $b * 255.); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - // like cmyk(100, 100, 100, 100) |
|
| 1675 | - if (preg_match('/cmyk\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1676 | - $c = $this->_convertSubColor($match[1]); |
|
| 1677 | - $m = $this->_convertSubColor($match[2]); |
|
| 1678 | - $y = $this->_convertSubColor($match[3]); |
|
| 1679 | - $k = $this->_convertSubColor($match[4]); |
|
| 1680 | - return array($c * 100., $m * 100., $y * 100., $k * 100.); |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - $res = false; |
|
| 1684 | - return array(0., 0., 0.); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * color value to convert |
|
| 1689 | - * |
|
| 1690 | - * @access protected |
|
| 1691 | - * @param string $c |
|
| 1692 | - * @return float $c 0.->1. |
|
| 1693 | - */ |
|
| 1694 | - protected function _convertSubColor($c) |
|
| 1695 | - { |
|
| 1696 | - if (substr($c, -1) == '%') { |
|
| 1697 | - $c = floatVal(substr($c, 0, -1)) / 100.; |
|
| 1698 | - } else { |
|
| 1699 | - $c = floatVal($c); |
|
| 1700 | - if ($c > 1) $c = $c / 255.; |
|
| 1701 | - } |
|
| 1702 | - |
|
| 1703 | - return $c; |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * read a css content |
|
| 1708 | - * |
|
| 1709 | - * @access protected |
|
| 1710 | - * @param string $code |
|
| 1711 | - */ |
|
| 1712 | - protected function _analyseStyle(&$code) |
|
| 1713 | - { |
|
| 1714 | - // clean the spaces |
|
| 1715 | - $code = preg_replace('/[\s]+/', ' ', $code); |
|
| 1716 | - |
|
| 1717 | - // remove the comments |
|
| 1718 | - $code = preg_replace('/\/\*.*?\*\//s', '', $code); |
|
| 1719 | - |
|
| 1720 | - // split each CSS code "selector { value }" |
|
| 1721 | - preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); |
|
| 1722 | - |
|
| 1723 | - // for each CSS code |
|
| 1724 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1725 | - |
|
| 1726 | - // selectors |
|
| 1727 | - $names = strtolower(trim($match[1][$k])); |
|
| 1728 | - |
|
| 1729 | - // css style |
|
| 1730 | - $styles = trim($match[2][$k]); |
|
| 1731 | - |
|
| 1732 | - // explode each value |
|
| 1733 | - $styles = explode(';', $styles); |
|
| 1734 | - |
|
| 1735 | - // parse each value |
|
| 1736 | - $css = array(); |
|
| 1737 | - foreach ($styles as $style) { |
|
| 1738 | - $tmp = explode(':', $style); |
|
| 1739 | - if (count($tmp) > 1) { |
|
| 1740 | - $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); |
|
| 1741 | - $css[trim(strtolower($cod))] = trim($tmp); |
|
| 1742 | - } |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // explode the names |
|
| 1746 | - $names = explode(',', $names); |
|
| 1747 | - |
|
| 1748 | - // save the values for each names |
|
| 1749 | - foreach ($names as $name) { |
|
| 1750 | - // clean the name |
|
| 1751 | - $name = trim($name); |
|
| 1752 | - |
|
| 1753 | - // if a selector with somethink lige :hover => continue |
|
| 1754 | - if (strpos($name, ':') !== false) continue; |
|
| 1755 | - |
|
| 1756 | - // save the value |
|
| 1757 | - if ( ! isset($this->css[$name])) |
|
| 1758 | - $this->css[$name] = $css; |
|
| 1759 | - else |
|
| 1760 | - $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1761 | - |
|
| 1762 | - } |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - // get he list of the keys |
|
| 1766 | - $this->cssKeys = array_flip(array_keys($this->css)); |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * Extract the css files from a html code |
|
| 1771 | - * |
|
| 1772 | - * @access public |
|
| 1773 | - * @param string &$html |
|
| 1774 | - * @param string $html |
|
| 1775 | - */ |
|
| 1776 | - public function readStyle(&$html) |
|
| 1777 | - { |
|
| 1778 | - // the CSS content |
|
| 1779 | - $style = ' '; |
|
| 1780 | - |
|
| 1781 | - // extract the link tags, and remove them in the html code |
|
| 1782 | - preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 1783 | - $html = preg_replace('/<link[^>]*>/isU', '', $html); |
|
| 1784 | - $html = preg_replace('/<\/link[^>]*>/isU', '', $html); |
|
| 1785 | - |
|
| 1786 | - // analyse each link tag |
|
| 1787 | - foreach ($match[1] as $code) { |
|
| 1788 | - $tmp = array(); |
|
| 1789 | - |
|
| 1790 | - // read the attributes name=value |
|
| 1791 | - $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 1792 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1793 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1794 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1795 | - } |
|
| 1796 | - |
|
| 1797 | - // read the attributes name="value" |
|
| 1798 | - $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 1799 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1800 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1801 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - // read the attributes name='value' |
|
| 1805 | - $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 1806 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1807 | - for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1808 | - $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - // if type text/css => we keep it |
|
| 1812 | - if (isset($tmp['type']) && strtolower($tmp['type']) == 'text/css' && isset($tmp['href'])) { |
|
| 1813 | - |
|
| 1814 | - // get the href |
|
| 1815 | - $url = $tmp['href']; |
|
| 1816 | - |
|
| 1817 | - // get the content of the css file |
|
| 1818 | - $content = @file_get_contents($url); |
|
| 1819 | - |
|
| 1820 | - // if "http://" in the url |
|
| 1821 | - if (strpos($url, 'http://') !== false) { |
|
| 1822 | - |
|
| 1823 | - // get the domain "http://xxx/" |
|
| 1824 | - $url = str_replace('http://', '', $url); |
|
| 1825 | - $url = explode('/', $url); |
|
| 1826 | - $urlMain = 'http://'.$url[0].'/'; |
|
| 1827 | - |
|
| 1828 | - // get the absolute url of the path |
|
| 1829 | - $urlSelf = $url; unset($urlSelf[count($urlSelf) - 1]); $urlSelf = 'http://'.implode('/', $urlSelf).'/'; |
|
| 1830 | - |
|
| 1831 | - // adapt the url in the css content |
|
| 1832 | - $content = preg_replace('/url\(([^\\\\][^)]*)\)/isU', 'url('.$urlSelf.'$1)', $content); |
|
| 1833 | - $content = preg_replace('/url\((\\\\[^)]*)\)/isU', 'url('.$urlMain.'$1)', $content); |
|
| 1834 | - } else { |
|
| 14 | + /** |
|
| 15 | + * reference to the pdf object |
|
| 16 | + * @var TCPDF |
|
| 17 | + */ |
|
| 18 | + protected $_pdf = null; |
|
| 19 | + |
|
| 20 | + protected $_htmlColor = array(); // list of the HTML colors |
|
| 21 | + protected $_onlyLeft = false; // flag if we are in a sub html => only "text-align:left" is used |
|
| 22 | + protected $_defaultFont = null; // default font to use if the asked font does not exist |
|
| 23 | + |
|
| 24 | + public $value = array(); // current values |
|
| 25 | + public $css = array(); // css values |
|
| 26 | + public $cssKeys = array(); // css key, for the execution order |
|
| 27 | + public $table = array(); // level history |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Constructor |
|
| 31 | + * |
|
| 32 | + * @param &HTML2PDF_myPdf reference to the PDF $object |
|
| 33 | + * @param HTML2PDF_myPdf $pdf |
|
| 34 | + * @access public |
|
| 35 | + */ |
|
| 36 | + public function __construct(&$pdf) |
|
| 37 | + { |
|
| 38 | + $this->_init(); |
|
| 39 | + $this->setPdfParent($pdf); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Set the HTML2PDF parent object |
|
| 44 | + * |
|
| 45 | + * @param &HTML2PDF reference to the HTML2PDF parent $object |
|
| 46 | + * @access public |
|
| 47 | + */ |
|
| 48 | + public function setPdfParent(&$pdf) |
|
| 49 | + { |
|
| 50 | + $this->_pdf = &$pdf; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Inform that we want only "test-align:left" because we are in a sub HTML |
|
| 55 | + * |
|
| 56 | + * @access public |
|
| 57 | + */ |
|
| 58 | + public function setOnlyLeft() |
|
| 59 | + { |
|
| 60 | + $this->value['text-align'] = 'left'; |
|
| 61 | + $this->_onlyLeft = true; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the vales of the parent, if exist |
|
| 66 | + * |
|
| 67 | + * @return array CSS values |
|
| 68 | + * @access public |
|
| 69 | + */ |
|
| 70 | + public function getOldValues() |
|
| 71 | + { |
|
| 72 | + return isset($this->table[count($this->table) - 1]) ? $this->table[count($this->table) - 1] : $this->value; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * define the Default Font to use, if the font does not exist, or if no font asked |
|
| 77 | + * |
|
| 78 | + * @param string default font-family. If null : Arial for no font asked, and error fot ont does not exist |
|
| 79 | + * @param string $default |
|
| 80 | + * @return string old default font-family |
|
| 81 | + * @access public |
|
| 82 | + */ |
|
| 83 | + public function setDefaultFont($default = null) |
|
| 84 | + { |
|
| 85 | + $old = $this->_defaultFont; |
|
| 86 | + $this->_defaultFont = $default; |
|
| 87 | + if ($default) { |
|
| 88 | + $this->value['font-family'] = $default; |
|
| 89 | + } |
|
| 90 | + return $old; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Init the object |
|
| 95 | + * |
|
| 96 | + * @access protected |
|
| 97 | + */ |
|
| 98 | + protected function _init() |
|
| 99 | + { |
|
| 100 | + // get the Web Colors from TCPDF |
|
| 101 | + require(K_PATH_MAIN.'htmlcolors.php'); |
|
| 102 | + $this->_htmlColor = $webcolor; |
|
| 103 | + |
|
| 104 | + // init the Style |
|
| 105 | + $this->table = array(); |
|
| 106 | + $this->value = array(); |
|
| 107 | + $this->initStyle(); |
|
| 108 | + |
|
| 109 | + // Init the styles without legacy |
|
| 110 | + $this->resetStyle(); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Init the CSS Style |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + */ |
|
| 118 | + public function initStyle() |
|
| 119 | + { |
|
| 120 | + $this->value['id_tag'] = 'body'; // tag name |
|
| 121 | + $this->value['id_name'] = null; // tag - attribute name |
|
| 122 | + $this->value['id_id'] = null; // tag - attribute id |
|
| 123 | + $this->value['id_class'] = null; // tag - attribute class |
|
| 124 | + $this->value['id_lst'] = array('*'); // tag - list of legacy |
|
| 125 | + $this->value['mini-size'] = 1.; // specific size report for sup, sub |
|
| 126 | + $this->value['mini-decal'] = 0; // specific position report for sup, sub |
|
| 127 | + $this->value['font-family'] = 'Arial'; |
|
| 128 | + $this->value['font-bold'] = false; |
|
| 129 | + $this->value['font-italic'] = false; |
|
| 130 | + $this->value['font-underline'] = false; |
|
| 131 | + $this->value['font-overline'] = false; |
|
| 132 | + $this->value['font-linethrough'] = false; |
|
| 133 | + $this->value['text-transform'] = 'none'; |
|
| 134 | + $this->value['font-size'] = $this->convertToMM('10pt'); |
|
| 135 | + $this->value['text-indent'] = 0; |
|
| 136 | + $this->value['text-align'] = 'left'; |
|
| 137 | + $this->value['vertical-align'] = 'middle'; |
|
| 138 | + $this->value['line-height'] = 'normal'; |
|
| 139 | + |
|
| 140 | + $this->value['position'] = null; |
|
| 141 | + $this->value['x'] = null; |
|
| 142 | + $this->value['y'] = null; |
|
| 143 | + $this->value['width'] = 0; |
|
| 144 | + $this->value['height'] = 0; |
|
| 145 | + $this->value['top'] = null; |
|
| 146 | + $this->value['right'] = null; |
|
| 147 | + $this->value['bottom'] = null; |
|
| 148 | + $this->value['left'] = null; |
|
| 149 | + $this->value['float'] = null; |
|
| 150 | + $this->value['display'] = null; |
|
| 151 | + $this->value['rotate'] = null; |
|
| 152 | + $this->value['overflow'] = 'visible'; |
|
| 153 | + |
|
| 154 | + $this->value['color'] = array(0, 0, 0); |
|
| 155 | + $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 156 | + $this->value['border'] = array(); |
|
| 157 | + $this->value['padding'] = array(); |
|
| 158 | + $this->value['margin'] = array(); |
|
| 159 | + $this->value['margin-auto'] = false; |
|
| 160 | + |
|
| 161 | + $this->value['list-style-type'] = ''; |
|
| 162 | + $this->value['list-style-image'] = ''; |
|
| 163 | + |
|
| 164 | + $this->value['xc'] = null; |
|
| 165 | + $this->value['yc'] = null; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Init the CSS Style without legacy |
|
| 170 | + * |
|
| 171 | + * @param string tag name |
|
| 172 | + * @access public |
|
| 173 | + */ |
|
| 174 | + public function resetStyle($tagName = '') |
|
| 175 | + { |
|
| 176 | + // prepare somme values |
|
| 177 | + $border = $this->readBorder('solid 1px #000000'); |
|
| 178 | + $units = array( |
|
| 179 | + '1px' => $this->convertToMM('1px'), |
|
| 180 | + '5px' => $this->convertToMM('5px'), |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + // prepare the Collapse attribute |
|
| 185 | + $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false; |
|
| 186 | + if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) $collapse = false; |
|
| 187 | + |
|
| 188 | + // set the global css values |
|
| 189 | + $this->value['position'] = null; |
|
| 190 | + $this->value['x'] = null; |
|
| 191 | + $this->value['y'] = null; |
|
| 192 | + $this->value['width'] = 0; |
|
| 193 | + $this->value['height'] = 0; |
|
| 194 | + $this->value['top'] = null; |
|
| 195 | + $this->value['right'] = null; |
|
| 196 | + $this->value['bottom'] = null; |
|
| 197 | + $this->value['left'] = null; |
|
| 198 | + $this->value['float'] = null; |
|
| 199 | + $this->value['display'] = null; |
|
| 200 | + $this->value['rotate'] = null; |
|
| 201 | + $this->value['overflow'] = 'visible'; |
|
| 202 | + $this->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null); |
|
| 203 | + $this->value['border'] = array( |
|
| 204 | + 't' => $this->readBorder('none'), |
|
| 205 | + 'r' => $this->readBorder('none'), |
|
| 206 | + 'b' => $this->readBorder('none'), |
|
| 207 | + 'l' => $this->readBorder('none'), |
|
| 208 | + 'radius' => array( |
|
| 209 | + 'tl' => array(0, 0), |
|
| 210 | + 'tr' => array(0, 0), |
|
| 211 | + 'br' => array(0, 0), |
|
| 212 | + 'bl' => array(0, 0) |
|
| 213 | + ), |
|
| 214 | + 'collapse' => $collapse, |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + // specific values for some tags |
|
| 218 | + if ( ! in_array($tagName, array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) { |
|
| 219 | + $this->value['margin'] = array('t'=>0, 'r'=>0, 'b'=>0, 'l'=>0); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (in_array($tagName, array('input', 'select', 'textarea'))) { |
|
| 223 | + $this->value['border']['t'] = null; |
|
| 224 | + $this->value['border']['r'] = null; |
|
| 225 | + $this->value['border']['b'] = null; |
|
| 226 | + $this->value['border']['l'] = null; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($tagName == 'p') { |
|
| 230 | + $this->value['margin']['t'] = null; |
|
| 231 | + $this->value['margin']['b'] = null; |
|
| 232 | + } |
|
| 233 | + if ($tagName == 'blockquote') { |
|
| 234 | + $this->value['margin']['t'] = 3; |
|
| 235 | + $this->value['margin']['r'] = 3; |
|
| 236 | + $this->value['margin']['b'] = 3; |
|
| 237 | + $this->value['margin']['l'] = 6; |
|
| 238 | + } |
|
| 239 | + $this->value['margin-auto'] = false; |
|
| 240 | + |
|
| 241 | + if (in_array($tagName, array('blockquote', 'div', 'fieldset'))) { |
|
| 242 | + $this->value['vertical-align'] = 'top'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if (in_array($tagName, array('fieldset', 'legend'))) { |
|
| 246 | + $this->value['border'] = array( |
|
| 247 | + 't' => $border, |
|
| 248 | + 'r' => $border, |
|
| 249 | + 'b' => $border, |
|
| 250 | + 'l' => $border, |
|
| 251 | + 'radius' => array( |
|
| 252 | + 'tl' => array($units['5px'], $units['5px']), |
|
| 253 | + 'tr' => array($units['5px'], $units['5px']), |
|
| 254 | + 'br' => array($units['5px'], $units['5px']), |
|
| 255 | + 'bl' => array($units['5px'], $units['5px']) |
|
| 256 | + ), |
|
| 257 | + 'collapse' => false, |
|
| 258 | + ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (in_array($tagName, array('ul', 'li'))) { |
|
| 262 | + $this->value['list-style-type'] = ''; |
|
| 263 | + $this->value['list-style-image'] = ''; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if ( ! in_array($tagName, array('tr', 'td'))) { |
|
| 267 | + $this->value['padding'] = array( |
|
| 268 | + 't' => 0, |
|
| 269 | + 'r' => 0, |
|
| 270 | + 'b' => 0, |
|
| 271 | + 'l' => 0 |
|
| 272 | + ); |
|
| 273 | + } else { |
|
| 274 | + $this->value['padding'] = array( |
|
| 275 | + 't' => $units['1px'], |
|
| 276 | + 'r' => $units['1px'], |
|
| 277 | + 'b' => $units['1px'], |
|
| 278 | + 'l' => $units['1px'] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + if ($tagName == 'hr') { |
|
| 283 | + $this->value['border'] = array( |
|
| 284 | + 't' => $border, |
|
| 285 | + 'r' => $border, |
|
| 286 | + 'b' => $border, |
|
| 287 | + 'l' => $border, |
|
| 288 | + 'radius' => array( |
|
| 289 | + 'tl' => array(0, 0), |
|
| 290 | + 'tr' => array(0, 0), |
|
| 291 | + 'br' => array(0, 0), |
|
| 292 | + 'bl' => array(0, 0) |
|
| 293 | + ), |
|
| 294 | + 'collapse' => false, |
|
| 295 | + ); |
|
| 296 | + $this->convertBackground('#FFFFFF', $this->value['background']); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->value['xc'] = null; |
|
| 300 | + $this->value['yc'] = null; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Init the PDF Font |
|
| 305 | + * |
|
| 306 | + * @access public |
|
| 307 | + */ |
|
| 308 | + public function fontSet() |
|
| 309 | + { |
|
| 310 | + $family = strtolower($this->value['font-family']); |
|
| 311 | + |
|
| 312 | + $b = ($this->value['font-bold'] ? 'B' : ''); |
|
| 313 | + $i = ($this->value['font-italic'] ? 'I' : ''); |
|
| 314 | + $u = ($this->value['font-underline'] ? 'U' : ''); |
|
| 315 | + $d = ($this->value['font-linethrough'] ? 'D' : ''); |
|
| 316 | + $o = ($this->value['font-overline'] ? 'O' : ''); |
|
| 317 | + |
|
| 318 | + // font style |
|
| 319 | + $style = $b.$i; |
|
| 320 | + |
|
| 321 | + if ($this->_defaultFont) { |
|
| 322 | + if ($family == 'arial') |
|
| 323 | + $family = 'helvetica'; |
|
| 324 | + elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 325 | + $style = ''; |
|
| 326 | + |
|
| 327 | + $fontkey = $family.$style; |
|
| 328 | + if ( ! $this->_pdf->isLoadedFont($fontkey)) |
|
| 329 | + $family = $this->_defaultFont; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + if ($family == 'arial') |
|
| 333 | + $family = 'helvetica'; |
|
| 334 | + elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 335 | + $style = ''; |
|
| 336 | + |
|
| 337 | + // complete style |
|
| 338 | + $style .= $u.$d.$o; |
|
| 339 | + |
|
| 340 | + // size : mm => pt |
|
| 341 | + $size = $this->value['font-size']; |
|
| 342 | + $size = 72 * $size / 25.4; |
|
| 343 | + |
|
| 344 | + // apply the font |
|
| 345 | + $this->_pdf->SetFont($family, $style, $this->value['mini-size'] * $size); |
|
| 346 | + $this->_pdf->setTextColorArray($this->value['color']); |
|
| 347 | + if ($this->value['background']['color']) { |
|
| 348 | + $this->_pdf->setFillColorArray($this->value['background']['color']); |
|
| 349 | + } else { |
|
| 350 | + $this->_pdf->setFillColor(255); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * add a level in the CSS history |
|
| 356 | + * |
|
| 357 | + * @access public |
|
| 358 | + */ |
|
| 359 | + public function save() |
|
| 360 | + { |
|
| 361 | + array_push($this->table, $this->value); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * remove a level in the CSS history |
|
| 366 | + * |
|
| 367 | + * @access public |
|
| 368 | + */ |
|
| 369 | + public function load() |
|
| 370 | + { |
|
| 371 | + if (count($this->table)) { |
|
| 372 | + $this->value = array_pop($this->table); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * restore the Y positiony (used after a span) |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + */ |
|
| 381 | + public function restorePosition() |
|
| 382 | + { |
|
| 383 | + if ($this->value['y'] == $this->_pdf->getY()) $this->_pdf->setY($this->value['yc'], false); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * set the New position for the current Tag |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + */ |
|
| 391 | + public function setPosition() |
|
| 392 | + { |
|
| 393 | + // get the current position |
|
| 394 | + $currentX = $this->_pdf->getX(); |
|
| 395 | + $currentY = $this->_pdf->getY(); |
|
| 396 | + |
|
| 397 | + // save it |
|
| 398 | + $this->value['xc'] = $currentX; |
|
| 399 | + $this->value['yc'] = $currentY; |
|
| 400 | + |
|
| 401 | + if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') { |
|
| 402 | + if ($this->value['right'] !== null) { |
|
| 403 | + $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; |
|
| 404 | + if ($this->value['margin']['r']) $x -= $this->value['margin']['r']; |
|
| 405 | + } else { |
|
| 406 | + $x = $this->value['left']; |
|
| 407 | + if ($this->value['margin']['l']) $x += $this->value['margin']['l']; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if ($this->value['bottom'] !== null) { |
|
| 411 | + $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; |
|
| 412 | + if ($this->value['margin']['b']) $y -= $this->value['margin']['b']; |
|
| 413 | + } else { |
|
| 414 | + $y = $this->value['top']; |
|
| 415 | + if ($this->value['margin']['t']) $y += $this->value['margin']['t']; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + if ($this->value['position'] == 'relative') { |
|
| 419 | + $this->value['x'] = $currentX + $x; |
|
| 420 | + $this->value['y'] = $currentY + $y; |
|
| 421 | + } else { |
|
| 422 | + $this->value['x'] = $this->_getLastAbsoluteX() + $x; |
|
| 423 | + $this->value['y'] = $this->_getLastAbsoluteY() + $y; |
|
| 424 | + } |
|
| 425 | + } else { |
|
| 426 | + $this->value['x'] = $currentX; |
|
| 427 | + $this->value['y'] = $currentY; |
|
| 428 | + if ($this->value['margin']['l']) $this->value['x'] += $this->value['margin']['l']; |
|
| 429 | + if ($this->value['margin']['t']) $this->value['y'] += $this->value['margin']['t']; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // save the new position |
|
| 433 | + $this->_pdf->setXY($this->value['x'], $this->value['y']); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Analise the CSS style to convert it into Form style |
|
| 438 | + * |
|
| 439 | + * @access public |
|
| 440 | + * @param array styles |
|
| 441 | + */ |
|
| 442 | + public function getFormStyle() |
|
| 443 | + { |
|
| 444 | + $prop = array(); |
|
| 445 | + |
|
| 446 | + $prop['alignment'] = $this->value['text-align']; |
|
| 447 | + |
|
| 448 | + if (isset($this->value['background']['color']) && is_array($this->value['background']['color'])) { |
|
| 449 | + $prop['fillColor'] = $this->value['background']['color']; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + if (isset($this->value['border']['t']['color'])) { |
|
| 453 | + $prop['strokeColor'] = $this->value['border']['t']['color']; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if (isset($this->value['border']['t']['width'])) { |
|
| 457 | + $prop['lineWidth'] = $this->value['border']['t']['width']; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + if (isset($this->value['border']['t']['type'])) { |
|
| 461 | + $prop['borderStyle'] = $this->value['border']['t']['type']; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + if ( ! empty($this->value['color'])) { |
|
| 465 | + $prop['textColor'] = $this->value['color']; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + if ( ! empty($this->value['font-size'])) { |
|
| 469 | + $prop['textSize'] = $this->value['font-size']; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + return $prop; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Analise the CSS style to convert it into SVG style |
|
| 477 | + * |
|
| 478 | + * @access public |
|
| 479 | + * @param string tag name |
|
| 480 | + * @param array styles |
|
| 481 | + * @param string $tagName |
|
| 482 | + */ |
|
| 483 | + public function getSvgStyle($tagName, &$param) |
|
| 484 | + { |
|
| 485 | + // prepare |
|
| 486 | + $tagName = strtolower($tagName); |
|
| 487 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 489 | + |
|
| 490 | + // read the class attribute |
|
| 491 | + $class = array(); |
|
| 492 | + $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 493 | + $tmp = explode(' ', $tmp); |
|
| 494 | + foreach ($tmp as $k => $v) { |
|
| 495 | + $v = trim($v); |
|
| 496 | + if ($v) { |
|
| 497 | + $class[] = $v; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // identify the tag, and the direct styles |
|
| 502 | + $this->value['id_tag'] = $tagName; |
|
| 503 | + $this->value['id_name'] = $name; |
|
| 504 | + $this->value['id_id'] = $id; |
|
| 505 | + $this->value['id_class'] = $class; |
|
| 506 | + $this->value['id_lst'] = array(); |
|
| 507 | + $this->value['id_lst'][] = '*'; |
|
| 508 | + $this->value['id_lst'][] = $tagName; |
|
| 509 | + if ( ! isset($this->value['svg'])) { |
|
| 510 | + $this->value['svg'] = array( |
|
| 511 | + 'stroke' => null, |
|
| 512 | + 'stroke-width' => $this->convertToMM('1pt'), |
|
| 513 | + 'fill' => null, |
|
| 514 | + 'fill-opacity' => null, |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (count($class)) { |
|
| 519 | + foreach ($class as $v) { |
|
| 520 | + $this->value['id_lst'][] = '*.'.$v; |
|
| 521 | + $this->value['id_lst'][] = '.'.$v; |
|
| 522 | + $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + if ($id) { |
|
| 526 | + $this->value['id_lst'][] = '*#'.$id; |
|
| 527 | + $this->value['id_lst'][] = '#'.$id; |
|
| 528 | + $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + // CSS style |
|
| 532 | + $styles = $this->_getFromCSS(); |
|
| 533 | + |
|
| 534 | + // adding the style from the tag |
|
| 535 | + $styles = array_merge($styles, $param['style']); |
|
| 536 | + |
|
| 537 | + if (isset($styles['stroke'])) $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 538 | + if (isset($styles['stroke-width'])) $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 539 | + if (isset($styles['fill'])) $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 540 | + if (isset($styles['fill-opacity'])) $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 541 | + |
|
| 542 | + return $this->value['svg']; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * analyse the css properties from the HTML parsing |
|
| 547 | + * |
|
| 548 | + * @access public |
|
| 549 | + * @param string $tagName |
|
| 550 | + * @param array $param |
|
| 551 | + * @param array $legacy |
|
| 552 | + */ |
|
| 553 | + public function analyse($tagName, &$param, $legacy = null) |
|
| 554 | + { |
|
| 555 | + // prepare the informations |
|
| 556 | + $tagName = strtolower($tagName); |
|
| 557 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 559 | + |
|
| 560 | + // get the class names to use |
|
| 561 | + $class = array(); |
|
| 562 | + $tmp = isset($param['class']) ? strtolower(trim($param['class'])) : ''; |
|
| 563 | + $tmp = explode(' ', $tmp); |
|
| 564 | + foreach ($tmp as $k => $v) { |
|
| 565 | + $v = trim($v); |
|
| 566 | + if ($v) { |
|
| 567 | + $class[] = $v; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // prepare the values, and the list of css tags to identify |
|
| 572 | + $this->value['id_tag'] = $tagName; |
|
| 573 | + $this->value['id_name'] = $name; |
|
| 574 | + $this->value['id_id'] = $id; |
|
| 575 | + $this->value['id_class'] = $class; |
|
| 576 | + $this->value['id_lst'] = array(); |
|
| 577 | + $this->value['id_lst'][] = '*'; |
|
| 578 | + $this->value['id_lst'][] = $tagName; |
|
| 579 | + if (count($class)) { |
|
| 580 | + foreach ($class as $v) { |
|
| 581 | + $this->value['id_lst'][] = '*.'.$v; |
|
| 582 | + $this->value['id_lst'][] = '.'.$v; |
|
| 583 | + $this->value['id_lst'][] = $tagName.'.'.$v; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if ($id) { |
|
| 587 | + $this->value['id_lst'][] = '*#'.$id; |
|
| 588 | + $this->value['id_lst'][] = '#'.$id; |
|
| 589 | + $this->value['id_lst'][] = $tagName.'#'.$id; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // get the css styles from class |
|
| 593 | + $styles = $this->_getFromCSS(); |
|
| 594 | + |
|
| 595 | + // merge with the css styles from tag |
|
| 596 | + $styles = array_merge($styles, $param['style']); |
|
| 597 | + if (isset($param['allwidth']) && ! isset($styles['width'])) $styles['width'] = '100%'; |
|
| 598 | + |
|
| 599 | + // reset some styles, depending on the tag name |
|
| 600 | + $this->resetStyle($tagName); |
|
| 601 | + |
|
| 602 | + // add the legacy values |
|
| 603 | + if ($legacy) { |
|
| 604 | + foreach ($legacy as $legacyName => $legacyValue) { |
|
| 605 | + if (is_array($legacyValue)) { |
|
| 606 | + foreach ($legacyValue as $legacy2Name => $legacy2Value) |
|
| 607 | + $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 608 | + } else { |
|
| 609 | + $this->value[$legacyName] = $legacyValue; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // some flags |
|
| 615 | + $correctWidth = false; |
|
| 616 | + $noWidth = true; |
|
| 617 | + |
|
| 618 | + // read all the css styles |
|
| 619 | + foreach ($styles as $nom => $val) { |
|
| 620 | + switch ($nom) |
|
| 621 | + { |
|
| 622 | + case 'font-family': |
|
| 623 | + $val = explode(',', $val); |
|
| 624 | + $val = trim($val[0]); |
|
| 625 | + if ($val) { |
|
| 626 | + $this->value['font-family'] = $val; |
|
| 627 | + } |
|
| 628 | + break; |
|
| 629 | + |
|
| 630 | + case 'font-weight': |
|
| 631 | + $this->value['font-bold'] = ($val == 'bold'); |
|
| 632 | + break; |
|
| 633 | + |
|
| 634 | + case 'font-style': |
|
| 635 | + $this->value['font-italic'] = ($val == 'italic'); |
|
| 636 | + break; |
|
| 637 | + |
|
| 638 | + case 'text-decoration': |
|
| 639 | + $val = explode(' ', $val); |
|
| 640 | + $this->value['font-underline'] = (in_array('underline', $val)); |
|
| 641 | + $this->value['font-overline'] = (in_array('overline', $val)); |
|
| 642 | + $this->value['font-linethrough'] = (in_array('line-through', $val)); |
|
| 643 | + break; |
|
| 644 | + |
|
| 645 | + case 'text-indent': |
|
| 646 | + $this->value['text-indent'] = $this->convertToMM($val); |
|
| 647 | + break; |
|
| 648 | + |
|
| 649 | + case 'text-transform': |
|
| 650 | + if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) $val = 'none'; |
|
| 651 | + $this->value['text-transform'] = $val; |
|
| 652 | + break; |
|
| 653 | + |
|
| 654 | + case 'font-size': |
|
| 655 | + $val = $this->convertToMM($val, $this->value['font-size']); |
|
| 656 | + if ($val) $this->value['font-size'] = $val; |
|
| 657 | + break; |
|
| 658 | + |
|
| 659 | + case 'color': |
|
| 660 | + $res = null; |
|
| 661 | + $this->value['color'] = $this->convertToColor($val, $res); |
|
| 662 | + if ($tagName == 'hr') { |
|
| 663 | + $this->value['border']['l']['color'] = $this->value['color']; |
|
| 664 | + $this->value['border']['t']['color'] = $this->value['color']; |
|
| 665 | + $this->value['border']['r']['color'] = $this->value['color']; |
|
| 666 | + $this->value['border']['b']['color'] = $this->value['color']; |
|
| 667 | + } |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'text-align': |
|
| 671 | + $val = strtolower($val); |
|
| 672 | + if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) $val = 'left'; |
|
| 673 | + $this->value['text-align'] = $val; |
|
| 674 | + break; |
|
| 675 | + |
|
| 676 | + case 'vertical-align': |
|
| 677 | + $this->value['vertical-align'] = $val; |
|
| 678 | + break; |
|
| 679 | + |
|
| 680 | + case 'width': |
|
| 681 | + $this->value['width'] = $this->convertToMM($val, $this->getLastWidth()); |
|
| 682 | + if ($this->value['width'] && substr($val, -1) == '%') $correctWidth = true; |
|
| 683 | + $noWidth = false; |
|
| 684 | + break; |
|
| 685 | + |
|
| 686 | + case 'height': |
|
| 687 | + $this->value['height'] = $this->convertToMM($val, $this->getLastHeight()); |
|
| 688 | + break; |
|
| 689 | + |
|
| 690 | + case 'line-height': |
|
| 691 | + if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val * 100).'%'; |
|
| 692 | + $this->value['line-height'] = $val; |
|
| 693 | + break; |
|
| 694 | + |
|
| 695 | + case 'rotate': |
|
| 696 | + if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) $val = null; |
|
| 697 | + if ($val < 0) $val += 360; |
|
| 698 | + $this->value['rotate'] = $val; |
|
| 699 | + break; |
|
| 700 | + |
|
| 701 | + case 'overflow': |
|
| 702 | + if ( ! in_array($val, array('visible', 'hidden'))) $val = 'visible'; |
|
| 703 | + $this->value['overflow'] = $val; |
|
| 704 | + break; |
|
| 705 | + |
|
| 706 | + case 'padding': |
|
| 707 | + $val = explode(' ', $val); |
|
| 708 | + foreach ($val as $k => $v) { |
|
| 709 | + $v = trim($v); |
|
| 710 | + if ($v != '') { |
|
| 711 | + $val[$k] = $v; |
|
| 712 | + } else { |
|
| 713 | + unset($val[$k]); |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + $val = array_values($val); |
|
| 717 | + $this->_duplicateBorder($val); |
|
| 718 | + $this->value['padding']['t'] = $this->convertToMM($val[0], 0); |
|
| 719 | + $this->value['padding']['r'] = $this->convertToMM($val[1], 0); |
|
| 720 | + $this->value['padding']['b'] = $this->convertToMM($val[2], 0); |
|
| 721 | + $this->value['padding']['l'] = $this->convertToMM($val[3], 0); |
|
| 722 | + break; |
|
| 723 | + |
|
| 724 | + case 'padding-top': |
|
| 725 | + $this->value['padding']['t'] = $this->convertToMM($val, 0); |
|
| 726 | + break; |
|
| 727 | + |
|
| 728 | + case 'padding-right': |
|
| 729 | + $this->value['padding']['r'] = $this->convertToMM($val, 0); |
|
| 730 | + break; |
|
| 731 | + |
|
| 732 | + case 'padding-bottom': |
|
| 733 | + $this->value['padding']['b'] = $this->convertToMM($val, 0); |
|
| 734 | + break; |
|
| 735 | + |
|
| 736 | + case 'padding-left': |
|
| 737 | + $this->value['padding']['l'] = $this->convertToMM($val, 0); |
|
| 738 | + break; |
|
| 739 | + |
|
| 740 | + case 'margin': |
|
| 741 | + if ($val == 'auto') { |
|
| 742 | + $this->value['margin-auto'] = true; |
|
| 743 | + break; |
|
| 744 | + } |
|
| 745 | + $val = explode(' ', $val); |
|
| 746 | + foreach ($val as $k => $v) { |
|
| 747 | + $v = trim($v); |
|
| 748 | + if ($v != '') { |
|
| 749 | + $val[$k] = $v; |
|
| 750 | + } else { |
|
| 751 | + unset($val[$k]); |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + $val = array_values($val); |
|
| 755 | + $this->_duplicateBorder($val); |
|
| 756 | + $this->value['margin']['t'] = $this->convertToMM($val[0], 0); |
|
| 757 | + $this->value['margin']['r'] = $this->convertToMM($val[1], 0); |
|
| 758 | + $this->value['margin']['b'] = $this->convertToMM($val[2], 0); |
|
| 759 | + $this->value['margin']['l'] = $this->convertToMM($val[3], 0); |
|
| 760 | + break; |
|
| 761 | + |
|
| 762 | + case 'margin-top': |
|
| 763 | + $this->value['margin']['t'] = $this->convertToMM($val, 0); |
|
| 764 | + break; |
|
| 765 | + |
|
| 766 | + case 'margin-right': |
|
| 767 | + $this->value['margin']['r'] = $this->convertToMM($val, 0); |
|
| 768 | + break; |
|
| 769 | + |
|
| 770 | + case 'margin-bottom': |
|
| 771 | + $this->value['margin']['b'] = $this->convertToMM($val, 0); |
|
| 772 | + break; |
|
| 773 | + |
|
| 774 | + case 'margin-left': |
|
| 775 | + $this->value['margin']['l'] = $this->convertToMM($val, 0); |
|
| 776 | + break; |
|
| 777 | + |
|
| 778 | + case 'border': |
|
| 779 | + $val = $this->readBorder($val); |
|
| 780 | + $this->value['border']['t'] = $val; |
|
| 781 | + $this->value['border']['r'] = $val; |
|
| 782 | + $this->value['border']['b'] = $val; |
|
| 783 | + $this->value['border']['l'] = $val; |
|
| 784 | + break; |
|
| 785 | + |
|
| 786 | + case 'border-style': |
|
| 787 | + $val = explode(' ', $val); |
|
| 788 | + foreach ($val as $valK => $valV) { |
|
| 789 | + if ( ! in_array($valV, array('solid', 'dotted', 'dashed'))) { |
|
| 790 | + $val[$valK] = null; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + $this->_duplicateBorder($val); |
|
| 794 | + if ($val[0]) { |
|
| 795 | + $this->value['border']['t']['type'] = $val[0]; |
|
| 796 | + } |
|
| 797 | + if ($val[1]) { |
|
| 798 | + $this->value['border']['r']['type'] = $val[1]; |
|
| 799 | + } |
|
| 800 | + if ($val[2]) { |
|
| 801 | + $this->value['border']['b']['type'] = $val[2]; |
|
| 802 | + } |
|
| 803 | + if ($val[3]) { |
|
| 804 | + $this->value['border']['l']['type'] = $val[3]; |
|
| 805 | + } |
|
| 806 | + break; |
|
| 807 | + |
|
| 808 | + case 'border-top-style': |
|
| 809 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 810 | + $this->value['border']['t']['type'] = $val; |
|
| 811 | + } |
|
| 812 | + break; |
|
| 813 | + |
|
| 814 | + case 'border-right-style': |
|
| 815 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 816 | + $this->value['border']['r']['type'] = $val; |
|
| 817 | + } |
|
| 818 | + break; |
|
| 819 | + |
|
| 820 | + case 'border-bottom-style': |
|
| 821 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 822 | + $this->value['border']['b']['type'] = $val; |
|
| 823 | + } |
|
| 824 | + break; |
|
| 825 | + |
|
| 826 | + case 'border-left-style': |
|
| 827 | + if (in_array($val, array('solid', 'dotted', 'dashed'))) { |
|
| 828 | + $this->value['border']['l']['type'] = $val; |
|
| 829 | + } |
|
| 830 | + break; |
|
| 831 | + |
|
| 832 | + case 'border-color': |
|
| 833 | + $res = false; |
|
| 834 | + $val = preg_replace('/,[\s]+/', ',', $val); |
|
| 835 | + $val = explode(' ', $val); |
|
| 836 | + foreach ($val as $valK => $valV) { |
|
| 837 | + $val[$valK] = $this->convertToColor($valV, $res); |
|
| 838 | + if ( ! $res) { |
|
| 839 | + $val[$valK] = null; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + $this->_duplicateBorder($val); |
|
| 843 | + if (is_array($val[0])) { |
|
| 844 | + $this->value['border']['t']['color'] = $val[0]; |
|
| 845 | + } |
|
| 846 | + if (is_array($val[1])) { |
|
| 847 | + $this->value['border']['r']['color'] = $val[1]; |
|
| 848 | + } |
|
| 849 | + if (is_array($val[2])) { |
|
| 850 | + $this->value['border']['b']['color'] = $val[2]; |
|
| 851 | + } |
|
| 852 | + if (is_array($val[3])) { |
|
| 853 | + $this->value['border']['l']['color'] = $val[3]; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + break; |
|
| 857 | + |
|
| 858 | + case 'border-top-color': |
|
| 859 | + $res = false; |
|
| 860 | + $val = $this->convertToColor($val, $res); |
|
| 861 | + if ($res) { |
|
| 862 | + $this->value['border']['t']['color'] = $val; |
|
| 863 | + } |
|
| 864 | + break; |
|
| 865 | + |
|
| 866 | + case 'border-right-color': |
|
| 867 | + $res = false; |
|
| 868 | + $val = $this->convertToColor($val, $res); |
|
| 869 | + if ($res) { |
|
| 870 | + $this->value['border']['r']['color'] = $val; |
|
| 871 | + } |
|
| 872 | + break; |
|
| 873 | + |
|
| 874 | + case 'border-bottom-color': |
|
| 875 | + $res = false; |
|
| 876 | + $val = $this->convertToColor($val, $res); |
|
| 877 | + if ($res) { |
|
| 878 | + $this->value['border']['b']['color'] = $val; |
|
| 879 | + } |
|
| 880 | + break; |
|
| 881 | + |
|
| 882 | + case 'border-left-color': |
|
| 883 | + $res = false; |
|
| 884 | + $val = $this->convertToColor($val, $res); |
|
| 885 | + if ($res) { |
|
| 886 | + $this->value['border']['l']['color'] = $val; |
|
| 887 | + } |
|
| 888 | + break; |
|
| 889 | + |
|
| 890 | + case 'border-width': |
|
| 891 | + $val = explode(' ', $val); |
|
| 892 | + foreach ($val as $valK => $valV) { |
|
| 893 | + $val[$valK] = $this->convertToMM($valV, 0); |
|
| 894 | + } |
|
| 895 | + $this->_duplicateBorder($val); |
|
| 896 | + if ($val[0]) $this->value['border']['t']['width'] = $val[0]; |
|
| 897 | + if ($val[1]) $this->value['border']['r']['width'] = $val[1]; |
|
| 898 | + if ($val[2]) $this->value['border']['b']['width'] = $val[2]; |
|
| 899 | + if ($val[3]) $this->value['border']['l']['width'] = $val[3]; |
|
| 900 | + break; |
|
| 901 | + |
|
| 902 | + case 'border-top-width': |
|
| 903 | + $val = $this->convertToMM($val, 0); |
|
| 904 | + if ($val) $this->value['border']['t']['width'] = $val; |
|
| 905 | + break; |
|
| 906 | + |
|
| 907 | + case 'border-right-width': |
|
| 908 | + $val = $this->convertToMM($val, 0); |
|
| 909 | + if ($val) $this->value['border']['r']['width'] = $val; |
|
| 910 | + break; |
|
| 911 | + |
|
| 912 | + case 'border-bottom-width': |
|
| 913 | + $val = $this->convertToMM($val, 0); |
|
| 914 | + if ($val) $this->value['border']['b']['width'] = $val; |
|
| 915 | + break; |
|
| 916 | + |
|
| 917 | + case 'border-left-width': |
|
| 918 | + $val = $this->convertToMM($val, 0); |
|
| 919 | + if ($val) $this->value['border']['l']['width'] = $val; |
|
| 920 | + break; |
|
| 921 | + |
|
| 922 | + case 'border-collapse': |
|
| 923 | + if ($tagName == 'table') $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 924 | + break; |
|
| 925 | + |
|
| 926 | + case 'border-radius': |
|
| 927 | + $val = explode('/', $val); |
|
| 928 | + if (count($val) > 2) { |
|
| 929 | + break; |
|
| 930 | + } |
|
| 931 | + $valH = $this->convertToRadius(trim($val[0])); |
|
| 932 | + if (count($valH) < 1 || count($valH) > 4) { |
|
| 933 | + break; |
|
| 934 | + } |
|
| 935 | + if ( ! isset($valH[1])) $valH[1] = $valH[0]; |
|
| 936 | + if ( ! isset($valH[2])) $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 937 | + if ( ! isset($valH[3])) $valH[3] = $valH[1]; |
|
| 938 | + if (isset($val[1])) { |
|
| 939 | + $valV = $this->convertToRadius(trim($val[1])); |
|
| 940 | + if (count($valV) < 1 || count($valV) > 4) { |
|
| 941 | + break; |
|
| 942 | + } |
|
| 943 | + if ( ! isset($valV[1])) $valV[1] = $valV[0]; |
|
| 944 | + if ( ! isset($valV[2])) $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 945 | + if ( ! isset($valV[3])) $valV[3] = $valV[1]; |
|
| 946 | + } else { |
|
| 947 | + $valV = $valH; |
|
| 948 | + } |
|
| 949 | + $this->value['border']['radius'] = array( |
|
| 950 | + 'tl' => array($valH[0], $valV[0]), |
|
| 951 | + 'tr' => array($valH[1], $valV[1]), |
|
| 952 | + 'br' => array($valH[2], $valV[2]), |
|
| 953 | + 'bl' => array($valH[3], $valV[3]) |
|
| 954 | + ); |
|
| 955 | + break; |
|
| 956 | + |
|
| 957 | + case 'border-top-left-radius': |
|
| 958 | + $val = $this->convertToRadius($val); |
|
| 959 | + if (count($val) < 1 || count($val) > 2) { |
|
| 960 | + break; |
|
| 961 | + } |
|
| 962 | + $this->value['border']['radius']['tl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 963 | + break; |
|
| 964 | + |
|
| 965 | + case 'border-top-right-radius': |
|
| 966 | + $val = $this->convertToRadius($val); |
|
| 967 | + if (count($val) < 1 || count($val) > 2) { |
|
| 968 | + break; |
|
| 969 | + } |
|
| 970 | + $this->value['border']['radius']['tr'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 971 | + break; |
|
| 972 | + |
|
| 973 | + case 'border-bottom-right-radius': |
|
| 974 | + $val = $this->convertToRadius($val); |
|
| 975 | + if (count($val) < 1 || count($val) > 2) { |
|
| 976 | + break; |
|
| 977 | + } |
|
| 978 | + $this->value['border']['radius']['br'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 979 | + break; |
|
| 980 | + |
|
| 981 | + case 'border-bottom-left-radius': |
|
| 982 | + $val = $this->convertToRadius($val); |
|
| 983 | + if (count($val) < 1 || count($val) > 2) { |
|
| 984 | + break; |
|
| 985 | + } |
|
| 986 | + $this->value['border']['radius']['bl'] = array($val[0], isset($val[1]) ? $val[1] : $val[0]); |
|
| 987 | + break; |
|
| 988 | + |
|
| 989 | + case 'border-top': |
|
| 990 | + $this->value['border']['t'] = $this->readBorder($val); |
|
| 991 | + break; |
|
| 992 | + |
|
| 993 | + case 'border-right': |
|
| 994 | + $this->value['border']['r'] = $this->readBorder($val); |
|
| 995 | + break; |
|
| 996 | + |
|
| 997 | + case 'border-bottom': |
|
| 998 | + $this->value['border']['b'] = $this->readBorder($val); |
|
| 999 | + break; |
|
| 1000 | + |
|
| 1001 | + case 'border-left': |
|
| 1002 | + $this->value['border']['l'] = $this->readBorder($val); |
|
| 1003 | + break; |
|
| 1004 | + |
|
| 1005 | + case 'background-color': |
|
| 1006 | + $this->value['background']['color'] = $this->convertBackgroundColor($val); |
|
| 1007 | + break; |
|
| 1008 | + |
|
| 1009 | + case 'background-image': |
|
| 1010 | + $this->value['background']['image'] = $this->convertBackgroundImage($val); |
|
| 1011 | + break; |
|
| 1012 | + |
|
| 1013 | + case 'background-position': |
|
| 1014 | + $res = null; |
|
| 1015 | + $this->value['background']['position'] = $this->convertBackgroundPosition($val, $res); |
|
| 1016 | + break; |
|
| 1017 | + |
|
| 1018 | + case 'background-repeat': |
|
| 1019 | + $this->value['background']['repeat'] = $this->convertBackgroundRepeat($val); |
|
| 1020 | + break; |
|
| 1021 | + |
|
| 1022 | + case 'background': |
|
| 1023 | + $this->convertBackground($val, $this->value['background']); |
|
| 1024 | + break; |
|
| 1025 | + |
|
| 1026 | + case 'position': |
|
| 1027 | + if ($val == 'absolute') $this->value['position'] = 'absolute'; |
|
| 1028 | + else if ($val == 'relative') $this->value['position'] = 'relative'; |
|
| 1029 | + else $this->value['position'] = null; |
|
| 1030 | + break; |
|
| 1031 | + |
|
| 1032 | + case 'float': |
|
| 1033 | + if ($val == 'left') $this->value['float'] = 'left'; |
|
| 1034 | + else if ($val == 'right') $this->value['float'] = 'right'; |
|
| 1035 | + else $this->value['float'] = null; |
|
| 1036 | + break; |
|
| 1037 | + |
|
| 1038 | + case 'display': |
|
| 1039 | + if ($val == 'inline') $this->value['display'] = 'inline'; |
|
| 1040 | + else if ($val == 'block') $this->value['display'] = 'block'; |
|
| 1041 | + else if ($val == 'none') $this->value['display'] = 'none'; |
|
| 1042 | + else $this->value['display'] = null; |
|
| 1043 | + break; |
|
| 1044 | + |
|
| 1045 | + case 'top': |
|
| 1046 | + case 'bottom': |
|
| 1047 | + case 'left': |
|
| 1048 | + case 'right': |
|
| 1049 | + $this->value[$nom] = $val; |
|
| 1050 | + break; |
|
| 1051 | + |
|
| 1052 | + case 'list-style': |
|
| 1053 | + case 'list-style-type': |
|
| 1054 | + case 'list-style-image': |
|
| 1055 | + if ($nom == 'list-style') $nom = 'list-style-type'; |
|
| 1056 | + $this->value[$nom] = $val; |
|
| 1057 | + break; |
|
| 1058 | + |
|
| 1059 | + default: |
|
| 1060 | + break; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + $return = true; |
|
| 1065 | + |
|
| 1066 | + // only for P tag |
|
| 1067 | + if ($this->value['margin']['t'] === null) $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1068 | + if ($this->value['margin']['b'] === null) $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1069 | + |
|
| 1070 | + // force the text align to left, if asked by html2pdf |
|
| 1071 | + if ($this->_onlyLeft) $this->value['text-align'] = 'left'; |
|
| 1072 | + |
|
| 1073 | + // correction on the width (quick box) |
|
| 1074 | + if ($noWidth && in_array($tagName, array('div', 'blockquote', 'fieldset')) && $this->value['position'] != 'absolute') { |
|
| 1075 | + $this->value['width'] = $this->getLastWidth(); |
|
| 1076 | + $this->value['width'] -= $this->value['margin']['l'] + $this->value['margin']['r']; |
|
| 1077 | + } else { |
|
| 1078 | + if ($correctWidth) { |
|
| 1079 | + if ( ! in_array($tagName, array('table', 'div', 'blockquote', 'fieldset', 'hr'))) { |
|
| 1080 | + $this->value['width'] -= $this->value['padding']['l'] + $this->value['padding']['r']; |
|
| 1081 | + $this->value['width'] -= $this->value['border']['l']['width'] + $this->value['border']['r']['width']; |
|
| 1082 | + } |
|
| 1083 | + if (in_array($tagName, array('th', 'td'))) { |
|
| 1084 | + $this->value['width'] -= $this->convertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
|
| 1085 | + $return = false; |
|
| 1086 | + } |
|
| 1087 | + if ($this->value['width'] < 0) $this->value['width'] = 0; |
|
| 1088 | + } else { |
|
| 1089 | + if ($this->value['width']) { |
|
| 1090 | + if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1091 | + if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1092 | + if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l']; |
|
| 1093 | + if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r']; |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + if ($this->value['height']) { |
|
| 1098 | + if ($this->value['border']['b']['width']) $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1099 | + if ($this->value['border']['t']['width']) $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1100 | + if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b']; |
|
| 1101 | + if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t']; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + if ($this->value['top'] != null) $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1105 | + if ($this->value['bottom'] != null) $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1106 | + if ($this->value['left'] != null) $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1107 | + if ($this->value['right'] != null) $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1108 | + |
|
| 1109 | + if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null; |
|
| 1110 | + if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null; |
|
| 1111 | + |
|
| 1112 | + return $return; |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * get the height of the current line |
|
| 1117 | + * |
|
| 1118 | + * @access public |
|
| 1119 | + * @return float $height in mm |
|
| 1120 | + */ |
|
| 1121 | + public function getLineHeight() |
|
| 1122 | + { |
|
| 1123 | + $val = $this->value['line-height']; |
|
| 1124 | + if ($val == 'normal') $val = '108%'; |
|
| 1125 | + return $this->convertToMM($val, $this->value['font-size']); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + /** |
|
| 1129 | + * get the width of the parent |
|
| 1130 | + * |
|
| 1131 | + * @access public |
|
| 1132 | + * @param boolean $mode true => adding padding and border |
|
| 1133 | + * @return float $width in mm |
|
| 1134 | + */ |
|
| 1135 | + public function getLastWidth($mode = false) |
|
| 1136 | + { |
|
| 1137 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1138 | + if ($this->table[$k]['width']) { |
|
| 1139 | + $w = $this->table[$k]['width']; |
|
| 1140 | + if ($mode) { |
|
| 1141 | + $w += $this->table[$k]['border']['l']['width'] + $this->table[$k]['padding']['l'] + 0.02; |
|
| 1142 | + $w += $this->table[$k]['border']['r']['width'] + $this->table[$k]['padding']['r'] + 0.02; |
|
| 1143 | + } |
|
| 1144 | + return $w; |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + return $this->_pdf->getW() - $this->_pdf->getlMargin() - $this->_pdf->getrMargin(); |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * get the height of the parent |
|
| 1152 | + * |
|
| 1153 | + * @access public |
|
| 1154 | + * @param boolean $mode true => adding padding and border |
|
| 1155 | + * @return float $height in mm |
|
| 1156 | + */ |
|
| 1157 | + public function getLastHeight($mode = false) |
|
| 1158 | + { |
|
| 1159 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1160 | + if ($this->table[$k]['height']) { |
|
| 1161 | + $h = $this->table[$k]['height']; |
|
| 1162 | + if ($mode) { |
|
| 1163 | + $h += $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; |
|
| 1164 | + $h += $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; |
|
| 1165 | + } |
|
| 1166 | + return $h; |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + return $this->_pdf->getH() - $this->_pdf->gettMargin() - $this->_pdf->getbMargin(); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * get the value of the float property |
|
| 1174 | + * |
|
| 1175 | + * @access public |
|
| 1176 | + * @return $float left/right |
|
| 1177 | + */ |
|
| 1178 | + public function getFloat() |
|
| 1179 | + { |
|
| 1180 | + if ($this->value['float'] == 'left') return 'left'; |
|
| 1181 | + if ($this->value['float'] == 'right') return 'right'; |
|
| 1182 | + return null; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * get the last value for a specific key |
|
| 1187 | + * |
|
| 1188 | + * @access public |
|
| 1189 | + * @param string $key |
|
| 1190 | + * @return mixed |
|
| 1191 | + */ |
|
| 1192 | + public function getLastValue($key) |
|
| 1193 | + { |
|
| 1194 | + $nb = count($this->table); |
|
| 1195 | + if ($nb > 0) { |
|
| 1196 | + return $this->table[$nb - 1][$key]; |
|
| 1197 | + } else { |
|
| 1198 | + return null; |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * get the last absolute X |
|
| 1204 | + * |
|
| 1205 | + * @access protected |
|
| 1206 | + * @return float $x |
|
| 1207 | + */ |
|
| 1208 | + protected function _getLastAbsoluteX() |
|
| 1209 | + { |
|
| 1210 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1211 | + if ($this->table[$k]['x'] && $this->table[$k]['position']) return $this->table[$k]['x']; |
|
| 1212 | + } |
|
| 1213 | + return $this->_pdf->getlMargin(); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * get the last absolute Y |
|
| 1218 | + * |
|
| 1219 | + * @access protected |
|
| 1220 | + * @return float $y |
|
| 1221 | + */ |
|
| 1222 | + protected function _getLastAbsoluteY() |
|
| 1223 | + { |
|
| 1224 | + for ($k = count($this->table) - 1; $k >= 0; $k--) { |
|
| 1225 | + if ($this->table[$k]['y'] && $this->table[$k]['position']) return $this->table[$k]['y']; |
|
| 1226 | + } |
|
| 1227 | + return $this->_pdf->gettMargin(); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * get the CSS properties of the current tag |
|
| 1232 | + * |
|
| 1233 | + * @access protected |
|
| 1234 | + * @return array $styles |
|
| 1235 | + */ |
|
| 1236 | + protected function _getFromCSS() |
|
| 1237 | + { |
|
| 1238 | + // styles to apply |
|
| 1239 | + $styles = array(); |
|
| 1240 | + |
|
| 1241 | + // list of the selectors to get in the CSS files |
|
| 1242 | + $getit = array(); |
|
| 1243 | + |
|
| 1244 | + // get the list of the selectors of each tags |
|
| 1245 | + $lst = array(); |
|
| 1246 | + $lst[] = $this->value['id_lst']; |
|
| 1247 | + for ($i = count($this->table) - 1; $i >= 0; $i--) { |
|
| 1248 | + $lst[] = $this->table[$i]['id_lst']; |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + // foreach selectors in the CSS files, verify if it match with the list of selectors |
|
| 1252 | + foreach ($this->cssKeys as $key => $num) { |
|
| 1253 | + if ($this->_getReccursiveStyle($key, $lst)) { |
|
| 1254 | + $getit[$key] = $num; |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + // if we have selectors |
|
| 1259 | + if (count($getit)) { |
|
| 1260 | + // get them, but in the definition order, because of priority |
|
| 1261 | + asort($getit); |
|
| 1262 | + foreach ($getit as $key => $val) { |
|
| 1263 | + $styles = array_merge($styles, $this->css[$key]); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + return $styles; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * identify if the selector $key match with the list of tag selectors |
|
| 1272 | + * |
|
| 1273 | + * @access protected |
|
| 1274 | + * @param string $key CSS selector to analyse |
|
| 1275 | + * @param array $lst list of the selectors of each tags |
|
| 1276 | + * @param string $next next step of parsing the selector |
|
| 1277 | + * @return boolean |
|
| 1278 | + */ |
|
| 1279 | + protected function _getReccursiveStyle($key, $lst, $next = null) |
|
| 1280 | + { |
|
| 1281 | + // if next step |
|
| 1282 | + if ($next !== null) { |
|
| 1283 | + // we remove this step |
|
| 1284 | + if ($next) { |
|
| 1285 | + $key = trim(substr($key, 0, -strlen($next))); |
|
| 1286 | + } |
|
| 1287 | + array_shift($lst); |
|
| 1288 | + |
|
| 1289 | + // if no more step to identify => return false |
|
| 1290 | + if ( ! count($lst)) { |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + // for each selector of the current step |
|
| 1296 | + foreach ($lst[0] as $name) { |
|
| 1297 | + // if selector = key => ok |
|
| 1298 | + if ($key == $name) { |
|
| 1299 | + return true; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // if the end of the key = the selector and the next step is ok => ok |
|
| 1303 | + if (substr($key, -strlen(' '.$name)) == ' '.$name && $this->_getReccursiveStyle($key, $lst, $name)) { |
|
| 1304 | + return true; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + // if we are not in the first step, we analyse the sub steps (the pareng tag of the current tag) |
|
| 1309 | + if ($next !== null && $this->_getReccursiveStyle($key, $lst, '')) { |
|
| 1310 | + return true; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + // no corresponding found |
|
| 1314 | + return false; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * Analyse a border |
|
| 1319 | + * |
|
| 1320 | + * @access public |
|
| 1321 | + * @param string $css css border properties |
|
| 1322 | + * @return array border properties |
|
| 1323 | + */ |
|
| 1324 | + public function readBorder($css) |
|
| 1325 | + { |
|
| 1326 | + // border none |
|
| 1327 | + $none = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0)); |
|
| 1328 | + |
|
| 1329 | + // default value |
|
| 1330 | + $type = 'solid'; |
|
| 1331 | + $width = $this->convertToMM('1pt'); |
|
| 1332 | + $color = array(0, 0, 0); |
|
| 1333 | + |
|
| 1334 | + // clean up the values |
|
| 1335 | + $css = explode(' ', $css); |
|
| 1336 | + foreach ($css as $k => $v) { |
|
| 1337 | + $v = trim($v); |
|
| 1338 | + if ($v) { |
|
| 1339 | + $css[$k] = $v; |
|
| 1340 | + } else { |
|
| 1341 | + unset($css[$k]); |
|
| 1342 | + } |
|
| 1343 | + } |
|
| 1344 | + $css = array_values($css); |
|
| 1345 | + |
|
| 1346 | + // read the values |
|
| 1347 | + $res = null; |
|
| 1348 | + foreach ($css as $value) { |
|
| 1349 | + |
|
| 1350 | + // if no border => return none |
|
| 1351 | + if ($value == 'none' || $value == 'hidden') { |
|
| 1352 | + return $none; |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + // try to convert the value as a distance |
|
| 1356 | + $tmp = $this->convertToMM($value); |
|
| 1357 | + |
|
| 1358 | + // if the convert is ok => it is a width |
|
| 1359 | + if ($tmp !== null) { |
|
| 1360 | + $width = $tmp; |
|
| 1361 | + // else, it could be the type |
|
| 1362 | + } else if (in_array($value, array('solid', 'dotted', 'dashed', 'double'))) { |
|
| 1363 | + $type = $value; |
|
| 1364 | + // else, it could be the color |
|
| 1365 | + } else { |
|
| 1366 | + $tmp = $this->convertToColor($value, $res); |
|
| 1367 | + if ($res) $color = $tmp; |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + // if no witdh => return none |
|
| 1372 | + if ( ! $width) return $none; |
|
| 1373 | + |
|
| 1374 | + // return the border properties |
|
| 1375 | + return array('type' => $type, 'width' => $width, 'color' => $color); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * duplicate the borders if needed |
|
| 1380 | + * |
|
| 1381 | + * @access protected |
|
| 1382 | + * @param &array $val |
|
| 1383 | + */ |
|
| 1384 | + protected function _duplicateBorder(&$val) |
|
| 1385 | + { |
|
| 1386 | + // 1 value => L => RTB |
|
| 1387 | + if (count($val) == 1) { |
|
| 1388 | + $val[1] = $val[0]; |
|
| 1389 | + $val[2] = $val[0]; |
|
| 1390 | + $val[3] = $val[0]; |
|
| 1391 | + // 2 values => L => R & T => B |
|
| 1392 | + } else if (count($val) == 2) { |
|
| 1393 | + $val[2] = $val[0]; |
|
| 1394 | + $val[3] = $val[1]; |
|
| 1395 | + // 3 values => T => B |
|
| 1396 | + } else if (count($val) == 3) { |
|
| 1397 | + $val[3] = $val[1]; |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * Analyse a background |
|
| 1403 | + * |
|
| 1404 | + * @access public |
|
| 1405 | + * @param string $css css background properties |
|
| 1406 | + * @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties) |
|
| 1407 | + */ |
|
| 1408 | + public function convertBackground($css, &$value) |
|
| 1409 | + { |
|
| 1410 | + // is there a image ? |
|
| 1411 | + $text = '/url\(([^)]*)\)/isU'; |
|
| 1412 | + if (preg_match($text, $css, $match)) { |
|
| 1413 | + // get the image |
|
| 1414 | + $value['image'] = $this->convertBackgroundImage($match[0]); |
|
| 1415 | + |
|
| 1416 | + // remove if from the css properties |
|
| 1417 | + $css = preg_replace($text, '', $css); |
|
| 1418 | + $css = preg_replace('/[\s]+/', ' ', $css); |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + // protect some spaces |
|
| 1422 | + $css = preg_replace('/,[\s]+/', ',', $css); |
|
| 1423 | + |
|
| 1424 | + // explode the values |
|
| 1425 | + $css = explode(' ', $css); |
|
| 1426 | + |
|
| 1427 | + // background position to parse |
|
| 1428 | + $pos = ''; |
|
| 1429 | + |
|
| 1430 | + // foreach value |
|
| 1431 | + foreach ($css as $val) { |
|
| 1432 | + // try to parse the value as a color |
|
| 1433 | + $ok = false; |
|
| 1434 | + $color = $this->convertToColor($val, $ok); |
|
| 1435 | + |
|
| 1436 | + // if ok => it is a color |
|
| 1437 | + if ($ok) { |
|
| 1438 | + $value['color'] = $color; |
|
| 1439 | + // else if transparent => no coloàr |
|
| 1440 | + } else if ($val == 'transparent') { |
|
| 1441 | + $value['color'] = null; |
|
| 1442 | + // else |
|
| 1443 | + } else { |
|
| 1444 | + // try to parse the value as a repeat |
|
| 1445 | + $repeat = $this->convertBackgroundRepeat($val); |
|
| 1446 | + |
|
| 1447 | + // if ok => it is repeat |
|
| 1448 | + if ($repeat) { |
|
| 1449 | + $value['repeat'] = $repeat; |
|
| 1450 | + // else => it could only be a position |
|
| 1451 | + } else { |
|
| 1452 | + $pos .= ($pos ? ' ' : '').$val; |
|
| 1453 | + } |
|
| 1454 | + } |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + // if we have a position to parse |
|
| 1458 | + if ($pos) { |
|
| 1459 | + // try to read it |
|
| 1460 | + $pos = $this->convertBackgroundPosition($pos, $ok); |
|
| 1461 | + if ($ok) { |
|
| 1462 | + $value['position'] = $pos; |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * parse a background color |
|
| 1469 | + * |
|
| 1470 | + * @access public |
|
| 1471 | + * @param string $css |
|
| 1472 | + * @return string $value |
|
| 1473 | + */ |
|
| 1474 | + public function convertBackgroundColor($css) |
|
| 1475 | + { |
|
| 1476 | + $res = null; |
|
| 1477 | + if ($css == 'transparent') return null; |
|
| 1478 | + else return $this->convertToColor($css, $res); |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * parse a background image |
|
| 1483 | + * |
|
| 1484 | + * @access public |
|
| 1485 | + * @param string $css |
|
| 1486 | + * @return string $value |
|
| 1487 | + */ |
|
| 1488 | + public function convertBackgroundImage($css) |
|
| 1489 | + { |
|
| 1490 | + if ($css == 'none') |
|
| 1491 | + return null; |
|
| 1492 | + else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) |
|
| 1493 | + return $match[1]; |
|
| 1494 | + else |
|
| 1495 | + return null; |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * parse a background position |
|
| 1500 | + * |
|
| 1501 | + * @access public |
|
| 1502 | + * @param string $css |
|
| 1503 | + * @param &boolean $res flag if conver is ok or not |
|
| 1504 | + * @return array ($x, $y) |
|
| 1505 | + */ |
|
| 1506 | + public function convertBackgroundPosition($css, &$res) |
|
| 1507 | + { |
|
| 1508 | + // init the res |
|
| 1509 | + $res = false; |
|
| 1510 | + |
|
| 1511 | + // explode the value |
|
| 1512 | + $css = explode(' ', $css); |
|
| 1513 | + |
|
| 1514 | + // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 |
|
| 1515 | + if (count($css) < 2) { |
|
| 1516 | + if ( ! $css[0]) return null; |
|
| 1517 | + $css[1] = 'center'; |
|
| 1518 | + } |
|
| 1519 | + if (count($css) > 2) return null; |
|
| 1520 | + |
|
| 1521 | + // prepare the values |
|
| 1522 | + $x = 0; |
|
| 1523 | + $y = 0; |
|
| 1524 | + $res = true; |
|
| 1525 | + |
|
| 1526 | + // convert the first value |
|
| 1527 | + if ($css[0] == 'left') $x = '0%'; |
|
| 1528 | + else if ($css[0] == 'center') $x = '50%'; |
|
| 1529 | + else if ($css[0] == 'right') $x = '100%'; |
|
| 1530 | + else if ($css[0] == 'top') $y = '0%'; |
|
| 1531 | + else if ($css[0] == 'bottom') $y = '100%'; |
|
| 1532 | + else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) $x = $css[0]; |
|
| 1533 | + else if ($this->convertToMM($css[0])) $x = $this->convertToMM($css[0]); |
|
| 1534 | + else $res = false; |
|
| 1535 | + |
|
| 1536 | + // convert the second value |
|
| 1537 | + if ($css[1] == 'left') $x = '0%'; |
|
| 1538 | + else if ($css[1] == 'right') $x = '100%'; |
|
| 1539 | + else if ($css[1] == 'top') $y = '0%'; |
|
| 1540 | + else if ($css[1] == 'center') $y = '50%'; |
|
| 1541 | + else if ($css[1] == 'bottom') $y = '100%'; |
|
| 1542 | + else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) $y = $css[1]; |
|
| 1543 | + else if ($this->convertToMM($css[1])) $y = $this->convertToMM($css[1]); |
|
| 1544 | + else $res = false; |
|
| 1545 | + |
|
| 1546 | + // return the values |
|
| 1547 | + return array($x, $y); |
|
| 1548 | + } |
|
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * parse a background repeat |
|
| 1552 | + * |
|
| 1553 | + * @access public |
|
| 1554 | + * @param string $css |
|
| 1555 | + * @return string $value |
|
| 1556 | + */ |
|
| 1557 | + public function convertBackgroundRepeat($css) |
|
| 1558 | + { |
|
| 1559 | + switch ($css) |
|
| 1560 | + { |
|
| 1561 | + case 'repeat': |
|
| 1562 | + return array(true, true); |
|
| 1563 | + case 'repeat-x': |
|
| 1564 | + return array(true, false); |
|
| 1565 | + case 'repeat-y': |
|
| 1566 | + return array(false, true); |
|
| 1567 | + case 'no-repeat': |
|
| 1568 | + return array(false, false); |
|
| 1569 | + } |
|
| 1570 | + return null; |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * convert a distance to mm |
|
| 1575 | + * |
|
| 1576 | + * @access public |
|
| 1577 | + * @param string $css distance to convert |
|
| 1578 | + * @param float $old parent distance |
|
| 1579 | + * @return float $value |
|
| 1580 | + */ |
|
| 1581 | + public function convertToMM($css, $old = 0.) |
|
| 1582 | + { |
|
| 1583 | + $css = trim($css); |
|
| 1584 | + if (preg_match('/^[0-9\.\-]+$/isU', $css)) $css .= 'px'; |
|
| 1585 | + if (preg_match('/^[0-9\.\-]+px$/isU', $css)) $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1586 | + else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1587 | + else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) $css = 25.4 * str_replace('in', '', $css); |
|
| 1588 | + else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) $css = 1. * str_replace('mm', '', $css); |
|
| 1589 | + else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1590 | + else $css = null; |
|
| 1591 | + |
|
| 1592 | + return $css; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * convert a css radius |
|
| 1597 | + * |
|
| 1598 | + * @access public |
|
| 1599 | + * @param string $css |
|
| 1600 | + * @return float $value |
|
| 1601 | + */ |
|
| 1602 | + public function convertToRadius($css) |
|
| 1603 | + { |
|
| 1604 | + // explode the value |
|
| 1605 | + $css = explode(' ', $css); |
|
| 1606 | + |
|
| 1607 | + foreach ($css as $k => $v) { |
|
| 1608 | + $v = trim($v); |
|
| 1609 | + if ($v) { |
|
| 1610 | + $v = $this->convertToMM($v, 0); |
|
| 1611 | + if ($v !== null) { |
|
| 1612 | + $css[$k] = $v; |
|
| 1613 | + } else { |
|
| 1614 | + unset($css[$k]); |
|
| 1615 | + } |
|
| 1616 | + } else { |
|
| 1617 | + unset($css[$k]); |
|
| 1618 | + } |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + return array_values($css); |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + /** |
|
| 1625 | + * convert a css color |
|
| 1626 | + * |
|
| 1627 | + * @access public |
|
| 1628 | + * @param string $css |
|
| 1629 | + * @param &boolean $res |
|
| 1630 | + * @return array (r,g, b) |
|
| 1631 | + */ |
|
| 1632 | + public function convertToColor($css, &$res) |
|
| 1633 | + { |
|
| 1634 | + // prepare the value |
|
| 1635 | + $css = trim($css); |
|
| 1636 | + $res = true; |
|
| 1637 | + |
|
| 1638 | + // if transparent => return null |
|
| 1639 | + if (strtolower($css) == 'transparent') return array(null, null, null); |
|
| 1640 | + |
|
| 1641 | + // HTML color |
|
| 1642 | + if (isset($this->_htmlColor[strtolower($css)])) { |
|
| 1643 | + $css = $this->_htmlColor[strtolower($css)]; |
|
| 1644 | + $r = floatVal(hexdec(substr($css, 0, 2))); |
|
| 1645 | + $v = floatVal(hexdec(substr($css, 2, 2))); |
|
| 1646 | + $b = floatVal(hexdec(substr($css, 4, 2))); |
|
| 1647 | + return array($r, $v, $b); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + // like #FFFFFF |
|
| 1651 | + if (preg_match('/^#[0-9A-Fa-f]{6}$/isU', $css)) { |
|
| 1652 | + $r = floatVal(hexdec(substr($css, 1, 2))); |
|
| 1653 | + $v = floatVal(hexdec(substr($css, 3, 2))); |
|
| 1654 | + $b = floatVal(hexdec(substr($css, 5, 2))); |
|
| 1655 | + return array($r, $v, $b); |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + // like #FFF |
|
| 1659 | + if (preg_match('/^#[0-9A-F]{3}$/isU', $css)) { |
|
| 1660 | + $r = floatVal(hexdec(substr($css, 1, 1).substr($css, 1, 1))); |
|
| 1661 | + $v = floatVal(hexdec(substr($css, 2, 1).substr($css, 2, 1))); |
|
| 1662 | + $b = floatVal(hexdec(substr($css, 3, 1).substr($css, 3, 1))); |
|
| 1663 | + return array($r, $v, $b); |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + // like rgb(100, 100, 100) |
|
| 1667 | + if (preg_match('/rgb\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1668 | + $r = $this->_convertSubColor($match[1]); |
|
| 1669 | + $v = $this->_convertSubColor($match[2]); |
|
| 1670 | + $b = $this->_convertSubColor($match[3]); |
|
| 1671 | + return array($r * 255., $v * 255., $b * 255.); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + // like cmyk(100, 100, 100, 100) |
|
| 1675 | + if (preg_match('/cmyk\([\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*,[\s]*([0-9%\.]+)[\s]*\)/isU', $css, $match)) { |
|
| 1676 | + $c = $this->_convertSubColor($match[1]); |
|
| 1677 | + $m = $this->_convertSubColor($match[2]); |
|
| 1678 | + $y = $this->_convertSubColor($match[3]); |
|
| 1679 | + $k = $this->_convertSubColor($match[4]); |
|
| 1680 | + return array($c * 100., $m * 100., $y * 100., $k * 100.); |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + $res = false; |
|
| 1684 | + return array(0., 0., 0.); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * color value to convert |
|
| 1689 | + * |
|
| 1690 | + * @access protected |
|
| 1691 | + * @param string $c |
|
| 1692 | + * @return float $c 0.->1. |
|
| 1693 | + */ |
|
| 1694 | + protected function _convertSubColor($c) |
|
| 1695 | + { |
|
| 1696 | + if (substr($c, -1) == '%') { |
|
| 1697 | + $c = floatVal(substr($c, 0, -1)) / 100.; |
|
| 1698 | + } else { |
|
| 1699 | + $c = floatVal($c); |
|
| 1700 | + if ($c > 1) $c = $c / 255.; |
|
| 1701 | + } |
|
| 1702 | + |
|
| 1703 | + return $c; |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * read a css content |
|
| 1708 | + * |
|
| 1709 | + * @access protected |
|
| 1710 | + * @param string $code |
|
| 1711 | + */ |
|
| 1712 | + protected function _analyseStyle(&$code) |
|
| 1713 | + { |
|
| 1714 | + // clean the spaces |
|
| 1715 | + $code = preg_replace('/[\s]+/', ' ', $code); |
|
| 1716 | + |
|
| 1717 | + // remove the comments |
|
| 1718 | + $code = preg_replace('/\/\*.*?\*\//s', '', $code); |
|
| 1719 | + |
|
| 1720 | + // split each CSS code "selector { value }" |
|
| 1721 | + preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); |
|
| 1722 | + |
|
| 1723 | + // for each CSS code |
|
| 1724 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1725 | + |
|
| 1726 | + // selectors |
|
| 1727 | + $names = strtolower(trim($match[1][$k])); |
|
| 1728 | + |
|
| 1729 | + // css style |
|
| 1730 | + $styles = trim($match[2][$k]); |
|
| 1731 | + |
|
| 1732 | + // explode each value |
|
| 1733 | + $styles = explode(';', $styles); |
|
| 1734 | + |
|
| 1735 | + // parse each value |
|
| 1736 | + $css = array(); |
|
| 1737 | + foreach ($styles as $style) { |
|
| 1738 | + $tmp = explode(':', $style); |
|
| 1739 | + if (count($tmp) > 1) { |
|
| 1740 | + $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); |
|
| 1741 | + $css[trim(strtolower($cod))] = trim($tmp); |
|
| 1742 | + } |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // explode the names |
|
| 1746 | + $names = explode(',', $names); |
|
| 1747 | + |
|
| 1748 | + // save the values for each names |
|
| 1749 | + foreach ($names as $name) { |
|
| 1750 | + // clean the name |
|
| 1751 | + $name = trim($name); |
|
| 1752 | + |
|
| 1753 | + // if a selector with somethink lige :hover => continue |
|
| 1754 | + if (strpos($name, ':') !== false) continue; |
|
| 1755 | + |
|
| 1756 | + // save the value |
|
| 1757 | + if ( ! isset($this->css[$name])) |
|
| 1758 | + $this->css[$name] = $css; |
|
| 1759 | + else |
|
| 1760 | + $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1761 | + |
|
| 1762 | + } |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + // get he list of the keys |
|
| 1766 | + $this->cssKeys = array_flip(array_keys($this->css)); |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * Extract the css files from a html code |
|
| 1771 | + * |
|
| 1772 | + * @access public |
|
| 1773 | + * @param string &$html |
|
| 1774 | + * @param string $html |
|
| 1775 | + */ |
|
| 1776 | + public function readStyle(&$html) |
|
| 1777 | + { |
|
| 1778 | + // the CSS content |
|
| 1779 | + $style = ' '; |
|
| 1780 | + |
|
| 1781 | + // extract the link tags, and remove them in the html code |
|
| 1782 | + preg_match_all('/<link([^>]*)>/isU', $html, $match); |
|
| 1783 | + $html = preg_replace('/<link[^>]*>/isU', '', $html); |
|
| 1784 | + $html = preg_replace('/<\/link[^>]*>/isU', '', $html); |
|
| 1785 | + |
|
| 1786 | + // analyse each link tag |
|
| 1787 | + foreach ($match[1] as $code) { |
|
| 1788 | + $tmp = array(); |
|
| 1789 | + |
|
| 1790 | + // read the attributes name=value |
|
| 1791 | + $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 1792 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1793 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1794 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + // read the attributes name="value" |
|
| 1798 | + $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 1799 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1800 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1801 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + // read the attributes name='value' |
|
| 1805 | + $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 1806 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 1807 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 1808 | + $tmp[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + // if type text/css => we keep it |
|
| 1812 | + if (isset($tmp['type']) && strtolower($tmp['type']) == 'text/css' && isset($tmp['href'])) { |
|
| 1813 | + |
|
| 1814 | + // get the href |
|
| 1815 | + $url = $tmp['href']; |
|
| 1816 | + |
|
| 1817 | + // get the content of the css file |
|
| 1818 | + $content = @file_get_contents($url); |
|
| 1819 | + |
|
| 1820 | + // if "http://" in the url |
|
| 1821 | + if (strpos($url, 'http://') !== false) { |
|
| 1822 | + |
|
| 1823 | + // get the domain "http://xxx/" |
|
| 1824 | + $url = str_replace('http://', '', $url); |
|
| 1825 | + $url = explode('/', $url); |
|
| 1826 | + $urlMain = 'http://'.$url[0].'/'; |
|
| 1827 | + |
|
| 1828 | + // get the absolute url of the path |
|
| 1829 | + $urlSelf = $url; unset($urlSelf[count($urlSelf) - 1]); $urlSelf = 'http://'.implode('/', $urlSelf).'/'; |
|
| 1830 | + |
|
| 1831 | + // adapt the url in the css content |
|
| 1832 | + $content = preg_replace('/url\(([^\\\\][^)]*)\)/isU', 'url('.$urlSelf.'$1)', $content); |
|
| 1833 | + $content = preg_replace('/url\((\\\\[^)]*)\)/isU', 'url('.$urlMain.'$1)', $content); |
|
| 1834 | + } else { |
|
| 1835 | 1835 | // @TODO correction on url in absolute on a local css content |
| 1836 | - // $content = preg_replace('/url\(([^)]*)\)/isU', 'url('.dirname($url).'/$1)', $content); |
|
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - // add to the CSS content |
|
| 1840 | - $style .= $content."\n"; |
|
| 1841 | - } |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - // extract the style tags des tags style, and remove them in the html code |
|
| 1845 | - preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 1846 | - $html = preg_replace('/<style[^>]*>(.*)<\/style[^>]*>/isU', '', $html); |
|
| 1847 | - |
|
| 1848 | - // analyse each style tags |
|
| 1849 | - foreach ($match[1] as $code) { |
|
| 1850 | - // add to the CSS content |
|
| 1851 | - $code = str_replace('<!--', '', $code); |
|
| 1852 | - $code = str_replace('-->', '', $code); |
|
| 1853 | - $style .= $code."\n"; |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - //analyse the css content |
|
| 1857 | - $this->_analyseStyle($style); |
|
| 1858 | - } |
|
| 1836 | + // $content = preg_replace('/url\(([^)]*)\)/isU', 'url('.dirname($url).'/$1)', $content); |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + // add to the CSS content |
|
| 1840 | + $style .= $content."\n"; |
|
| 1841 | + } |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + // extract the style tags des tags style, and remove them in the html code |
|
| 1845 | + preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match); |
|
| 1846 | + $html = preg_replace('/<style[^>]*>(.*)<\/style[^>]*>/isU', '', $html); |
|
| 1847 | + |
|
| 1848 | + // analyse each style tags |
|
| 1849 | + foreach ($match[1] as $code) { |
|
| 1850 | + // add to the CSS content |
|
| 1851 | + $code = str_replace('<!--', '', $code); |
|
| 1852 | + $code = str_replace('-->', '', $code); |
|
| 1853 | + $style .= $code."\n"; |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + //analyse the css content |
|
| 1857 | + $this->_analyseStyle($style); |
|
| 1858 | + } |
|
| 1859 | 1859 | } |
| 1860 | 1860 | \ No newline at end of file |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | { |
| 485 | 485 | // prepare |
| 486 | 486 | $tagName = strtolower($tagName); |
| 487 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 487 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | 488 | $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
| 489 | 489 | |
| 490 | 490 | // read the class attribute |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | { |
| 555 | 555 | // prepare the informations |
| 556 | 556 | $tagName = strtolower($tagName); |
| 557 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 557 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | 558 | $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
| 559 | 559 | |
| 560 | 560 | // get the class names to use |
@@ -183,7 +183,9 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | // prepare the Collapse attribute |
| 185 | 185 | $collapse = isset($this->value['border']['collapse']) ? $this->value['border']['collapse'] : false; |
| 186 | - if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) $collapse = false; |
|
| 186 | + if ( ! in_array($tagName, array('tr', 'td', 'th', 'thead', 'tbody', 'tfoot'))) { |
|
| 187 | + $collapse = false; |
|
| 188 | + } |
|
| 187 | 189 | |
| 188 | 190 | // set the global css values |
| 189 | 191 | $this->value['position'] = null; |
@@ -319,20 +321,23 @@ discard block |
||
| 319 | 321 | $style = $b.$i; |
| 320 | 322 | |
| 321 | 323 | if ($this->_defaultFont) { |
| 322 | - if ($family == 'arial') |
|
| 323 | - $family = 'helvetica'; |
|
| 324 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 325 | - $style = ''; |
|
| 324 | + if ($family == 'arial') { |
|
| 325 | + $family = 'helvetica'; |
|
| 326 | + } elseif ($family == 'symbol' || $family == 'zapfdingbats') { |
|
| 327 | + $style = ''; |
|
| 328 | + } |
|
| 326 | 329 | |
| 327 | 330 | $fontkey = $family.$style; |
| 328 | - if ( ! $this->_pdf->isLoadedFont($fontkey)) |
|
| 329 | - $family = $this->_defaultFont; |
|
| 331 | + if ( ! $this->_pdf->isLoadedFont($fontkey)) { |
|
| 332 | + $family = $this->_defaultFont; |
|
| 333 | + } |
|
| 330 | 334 | } |
| 331 | 335 | |
| 332 | - if ($family == 'arial') |
|
| 333 | - $family = 'helvetica'; |
|
| 334 | - elseif ($family == 'symbol' || $family == 'zapfdingbats') |
|
| 335 | - $style = ''; |
|
| 336 | + if ($family == 'arial') { |
|
| 337 | + $family = 'helvetica'; |
|
| 338 | + } elseif ($family == 'symbol' || $family == 'zapfdingbats') { |
|
| 339 | + $style = ''; |
|
| 340 | + } |
|
| 336 | 341 | |
| 337 | 342 | // complete style |
| 338 | 343 | $style .= $u.$d.$o; |
@@ -380,7 +385,9 @@ discard block |
||
| 380 | 385 | */ |
| 381 | 386 | public function restorePosition() |
| 382 | 387 | { |
| 383 | - if ($this->value['y'] == $this->_pdf->getY()) $this->_pdf->setY($this->value['yc'], false); |
|
| 388 | + if ($this->value['y'] == $this->_pdf->getY()) { |
|
| 389 | + $this->_pdf->setY($this->value['yc'], false); |
|
| 390 | + } |
|
| 384 | 391 | } |
| 385 | 392 | |
| 386 | 393 | /** |
@@ -401,18 +408,26 @@ discard block |
||
| 401 | 408 | if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') { |
| 402 | 409 | if ($this->value['right'] !== null) { |
| 403 | 410 | $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; |
| 404 | - if ($this->value['margin']['r']) $x -= $this->value['margin']['r']; |
|
| 411 | + if ($this->value['margin']['r']) { |
|
| 412 | + $x -= $this->value['margin']['r']; |
|
| 413 | + } |
|
| 405 | 414 | } else { |
| 406 | 415 | $x = $this->value['left']; |
| 407 | - if ($this->value['margin']['l']) $x += $this->value['margin']['l']; |
|
| 416 | + if ($this->value['margin']['l']) { |
|
| 417 | + $x += $this->value['margin']['l']; |
|
| 418 | + } |
|
| 408 | 419 | } |
| 409 | 420 | |
| 410 | 421 | if ($this->value['bottom'] !== null) { |
| 411 | 422 | $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; |
| 412 | - if ($this->value['margin']['b']) $y -= $this->value['margin']['b']; |
|
| 423 | + if ($this->value['margin']['b']) { |
|
| 424 | + $y -= $this->value['margin']['b']; |
|
| 425 | + } |
|
| 413 | 426 | } else { |
| 414 | 427 | $y = $this->value['top']; |
| 415 | - if ($this->value['margin']['t']) $y += $this->value['margin']['t']; |
|
| 428 | + if ($this->value['margin']['t']) { |
|
| 429 | + $y += $this->value['margin']['t']; |
|
| 430 | + } |
|
| 416 | 431 | } |
| 417 | 432 | |
| 418 | 433 | if ($this->value['position'] == 'relative') { |
@@ -425,8 +440,12 @@ discard block |
||
| 425 | 440 | } else { |
| 426 | 441 | $this->value['x'] = $currentX; |
| 427 | 442 | $this->value['y'] = $currentY; |
| 428 | - if ($this->value['margin']['l']) $this->value['x'] += $this->value['margin']['l']; |
|
| 429 | - if ($this->value['margin']['t']) $this->value['y'] += $this->value['margin']['t']; |
|
| 443 | + if ($this->value['margin']['l']) { |
|
| 444 | + $this->value['x'] += $this->value['margin']['l']; |
|
| 445 | + } |
|
| 446 | + if ($this->value['margin']['t']) { |
|
| 447 | + $this->value['y'] += $this->value['margin']['t']; |
|
| 448 | + } |
|
| 430 | 449 | } |
| 431 | 450 | |
| 432 | 451 | // save the new position |
@@ -484,8 +503,12 @@ discard block |
||
| 484 | 503 | { |
| 485 | 504 | // prepare |
| 486 | 505 | $tagName = strtolower($tagName); |
| 487 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 488 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 506 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) { |
|
| 507 | + $id = null; |
|
| 508 | + } |
|
| 509 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) { |
|
| 510 | + $name = null; |
|
| 511 | + } |
|
| 489 | 512 | |
| 490 | 513 | // read the class attribute |
| 491 | 514 | $class = array(); |
@@ -534,10 +557,18 @@ discard block |
||
| 534 | 557 | // adding the style from the tag |
| 535 | 558 | $styles = array_merge($styles, $param['style']); |
| 536 | 559 | |
| 537 | - if (isset($styles['stroke'])) $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 538 | - if (isset($styles['stroke-width'])) $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 539 | - if (isset($styles['fill'])) $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 540 | - if (isset($styles['fill-opacity'])) $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 560 | + if (isset($styles['stroke'])) { |
|
| 561 | + $this->value['svg']['stroke'] = $this->convertToColor($styles['stroke'], $res); |
|
| 562 | + } |
|
| 563 | + if (isset($styles['stroke-width'])) { |
|
| 564 | + $this->value['svg']['stroke-width'] = $this->convertToMM($styles['stroke-width']); |
|
| 565 | + } |
|
| 566 | + if (isset($styles['fill'])) { |
|
| 567 | + $this->value['svg']['fill'] = $this->convertToColor($styles['fill'], $res); |
|
| 568 | + } |
|
| 569 | + if (isset($styles['fill-opacity'])) { |
|
| 570 | + $this->value['svg']['fill-opacity'] = 1. * $styles['fill-opacity']; |
|
| 571 | + } |
|
| 541 | 572 | |
| 542 | 573 | return $this->value['svg']; |
| 543 | 574 | } |
@@ -554,8 +585,12 @@ discard block |
||
| 554 | 585 | { |
| 555 | 586 | // prepare the informations |
| 556 | 587 | $tagName = strtolower($tagName); |
| 557 | - $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) $id = null; |
|
| 558 | - $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) $name = null; |
|
| 588 | + $id = isset($param['id']) ? strtolower(trim($param['id'])) : null; if ( ! $id) { |
|
| 589 | + $id = null; |
|
| 590 | + } |
|
| 591 | + $name = isset($param['name']) ? strtolower(trim($param['name'])) : null; if ( ! $name) { |
|
| 592 | + $name = null; |
|
| 593 | + } |
|
| 559 | 594 | |
| 560 | 595 | // get the class names to use |
| 561 | 596 | $class = array(); |
@@ -594,7 +629,9 @@ discard block |
||
| 594 | 629 | |
| 595 | 630 | // merge with the css styles from tag |
| 596 | 631 | $styles = array_merge($styles, $param['style']); |
| 597 | - if (isset($param['allwidth']) && ! isset($styles['width'])) $styles['width'] = '100%'; |
|
| 632 | + if (isset($param['allwidth']) && ! isset($styles['width'])) { |
|
| 633 | + $styles['width'] = '100%'; |
|
| 634 | + } |
|
| 598 | 635 | |
| 599 | 636 | // reset some styles, depending on the tag name |
| 600 | 637 | $this->resetStyle($tagName); |
@@ -603,8 +640,9 @@ discard block |
||
| 603 | 640 | if ($legacy) { |
| 604 | 641 | foreach ($legacy as $legacyName => $legacyValue) { |
| 605 | 642 | if (is_array($legacyValue)) { |
| 606 | - foreach ($legacyValue as $legacy2Name => $legacy2Value) |
|
| 607 | - $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 643 | + foreach ($legacyValue as $legacy2Name => $legacy2Value) { |
|
| 644 | + $this->value[$legacyName][$legacy2Name] = $legacy2Value; |
|
| 645 | + } |
|
| 608 | 646 | } else { |
| 609 | 647 | $this->value[$legacyName] = $legacyValue; |
| 610 | 648 | } |
@@ -647,13 +685,17 @@ discard block |
||
| 647 | 685 | break; |
| 648 | 686 | |
| 649 | 687 | case 'text-transform': |
| 650 | - if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) $val = 'none'; |
|
| 688 | + if ( ! in_array($val, array('none', 'capitalize', 'uppercase', 'lowercase'))) { |
|
| 689 | + $val = 'none'; |
|
| 690 | + } |
|
| 651 | 691 | $this->value['text-transform'] = $val; |
| 652 | 692 | break; |
| 653 | 693 | |
| 654 | 694 | case 'font-size': |
| 655 | 695 | $val = $this->convertToMM($val, $this->value['font-size']); |
| 656 | - if ($val) $this->value['font-size'] = $val; |
|
| 696 | + if ($val) { |
|
| 697 | + $this->value['font-size'] = $val; |
|
| 698 | + } |
|
| 657 | 699 | break; |
| 658 | 700 | |
| 659 | 701 | case 'color': |
@@ -669,7 +711,9 @@ discard block |
||
| 669 | 711 | |
| 670 | 712 | case 'text-align': |
| 671 | 713 | $val = strtolower($val); |
| 672 | - if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) $val = 'left'; |
|
| 714 | + if ( ! in_array($val, array('left', 'right', 'center', 'justify', 'li_right'))) { |
|
| 715 | + $val = 'left'; |
|
| 716 | + } |
|
| 673 | 717 | $this->value['text-align'] = $val; |
| 674 | 718 | break; |
| 675 | 719 | |
@@ -679,7 +723,9 @@ discard block |
||
| 679 | 723 | |
| 680 | 724 | case 'width': |
| 681 | 725 | $this->value['width'] = $this->convertToMM($val, $this->getLastWidth()); |
| 682 | - if ($this->value['width'] && substr($val, -1) == '%') $correctWidth = true; |
|
| 726 | + if ($this->value['width'] && substr($val, -1) == '%') { |
|
| 727 | + $correctWidth = true; |
|
| 728 | + } |
|
| 683 | 729 | $noWidth = false; |
| 684 | 730 | break; |
| 685 | 731 | |
@@ -688,18 +734,26 @@ discard block |
||
| 688 | 734 | break; |
| 689 | 735 | |
| 690 | 736 | case 'line-height': |
| 691 | - if (preg_match('/^[0-9\.]+$/isU', $val)) $val = floor($val * 100).'%'; |
|
| 737 | + if (preg_match('/^[0-9\.]+$/isU', $val)) { |
|
| 738 | + $val = floor($val * 100).'%'; |
|
| 739 | + } |
|
| 692 | 740 | $this->value['line-height'] = $val; |
| 693 | 741 | break; |
| 694 | 742 | |
| 695 | 743 | case 'rotate': |
| 696 | - if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) $val = null; |
|
| 697 | - if ($val < 0) $val += 360; |
|
| 744 | + if ( ! in_array($val, array(0, -90, 90, 180, 270, -180, -270))) { |
|
| 745 | + $val = null; |
|
| 746 | + } |
|
| 747 | + if ($val < 0) { |
|
| 748 | + $val += 360; |
|
| 749 | + } |
|
| 698 | 750 | $this->value['rotate'] = $val; |
| 699 | 751 | break; |
| 700 | 752 | |
| 701 | 753 | case 'overflow': |
| 702 | - if ( ! in_array($val, array('visible', 'hidden'))) $val = 'visible'; |
|
| 754 | + if ( ! in_array($val, array('visible', 'hidden'))) { |
|
| 755 | + $val = 'visible'; |
|
| 756 | + } |
|
| 703 | 757 | $this->value['overflow'] = $val; |
| 704 | 758 | break; |
| 705 | 759 | |
@@ -893,34 +947,52 @@ discard block |
||
| 893 | 947 | $val[$valK] = $this->convertToMM($valV, 0); |
| 894 | 948 | } |
| 895 | 949 | $this->_duplicateBorder($val); |
| 896 | - if ($val[0]) $this->value['border']['t']['width'] = $val[0]; |
|
| 897 | - if ($val[1]) $this->value['border']['r']['width'] = $val[1]; |
|
| 898 | - if ($val[2]) $this->value['border']['b']['width'] = $val[2]; |
|
| 899 | - if ($val[3]) $this->value['border']['l']['width'] = $val[3]; |
|
| 950 | + if ($val[0]) { |
|
| 951 | + $this->value['border']['t']['width'] = $val[0]; |
|
| 952 | + } |
|
| 953 | + if ($val[1]) { |
|
| 954 | + $this->value['border']['r']['width'] = $val[1]; |
|
| 955 | + } |
|
| 956 | + if ($val[2]) { |
|
| 957 | + $this->value['border']['b']['width'] = $val[2]; |
|
| 958 | + } |
|
| 959 | + if ($val[3]) { |
|
| 960 | + $this->value['border']['l']['width'] = $val[3]; |
|
| 961 | + } |
|
| 900 | 962 | break; |
| 901 | 963 | |
| 902 | 964 | case 'border-top-width': |
| 903 | 965 | $val = $this->convertToMM($val, 0); |
| 904 | - if ($val) $this->value['border']['t']['width'] = $val; |
|
| 966 | + if ($val) { |
|
| 967 | + $this->value['border']['t']['width'] = $val; |
|
| 968 | + } |
|
| 905 | 969 | break; |
| 906 | 970 | |
| 907 | 971 | case 'border-right-width': |
| 908 | 972 | $val = $this->convertToMM($val, 0); |
| 909 | - if ($val) $this->value['border']['r']['width'] = $val; |
|
| 973 | + if ($val) { |
|
| 974 | + $this->value['border']['r']['width'] = $val; |
|
| 975 | + } |
|
| 910 | 976 | break; |
| 911 | 977 | |
| 912 | 978 | case 'border-bottom-width': |
| 913 | 979 | $val = $this->convertToMM($val, 0); |
| 914 | - if ($val) $this->value['border']['b']['width'] = $val; |
|
| 980 | + if ($val) { |
|
| 981 | + $this->value['border']['b']['width'] = $val; |
|
| 982 | + } |
|
| 915 | 983 | break; |
| 916 | 984 | |
| 917 | 985 | case 'border-left-width': |
| 918 | 986 | $val = $this->convertToMM($val, 0); |
| 919 | - if ($val) $this->value['border']['l']['width'] = $val; |
|
| 987 | + if ($val) { |
|
| 988 | + $this->value['border']['l']['width'] = $val; |
|
| 989 | + } |
|
| 920 | 990 | break; |
| 921 | 991 | |
| 922 | 992 | case 'border-collapse': |
| 923 | - if ($tagName == 'table') $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 993 | + if ($tagName == 'table') { |
|
| 994 | + $this->value['border']['collapse'] = ($val == 'collapse'); |
|
| 995 | + } |
|
| 924 | 996 | break; |
| 925 | 997 | |
| 926 | 998 | case 'border-radius': |
@@ -932,17 +1004,29 @@ discard block |
||
| 932 | 1004 | if (count($valH) < 1 || count($valH) > 4) { |
| 933 | 1005 | break; |
| 934 | 1006 | } |
| 935 | - if ( ! isset($valH[1])) $valH[1] = $valH[0]; |
|
| 936 | - if ( ! isset($valH[2])) $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 937 | - if ( ! isset($valH[3])) $valH[3] = $valH[1]; |
|
| 1007 | + if ( ! isset($valH[1])) { |
|
| 1008 | + $valH[1] = $valH[0]; |
|
| 1009 | + } |
|
| 1010 | + if ( ! isset($valH[2])) { |
|
| 1011 | + $valH = array($valH[0], $valH[0], $valH[1], $valH[1]); |
|
| 1012 | + } |
|
| 1013 | + if ( ! isset($valH[3])) { |
|
| 1014 | + $valH[3] = $valH[1]; |
|
| 1015 | + } |
|
| 938 | 1016 | if (isset($val[1])) { |
| 939 | 1017 | $valV = $this->convertToRadius(trim($val[1])); |
| 940 | 1018 | if (count($valV) < 1 || count($valV) > 4) { |
| 941 | 1019 | break; |
| 942 | 1020 | } |
| 943 | - if ( ! isset($valV[1])) $valV[1] = $valV[0]; |
|
| 944 | - if ( ! isset($valV[2])) $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 945 | - if ( ! isset($valV[3])) $valV[3] = $valV[1]; |
|
| 1021 | + if ( ! isset($valV[1])) { |
|
| 1022 | + $valV[1] = $valV[0]; |
|
| 1023 | + } |
|
| 1024 | + if ( ! isset($valV[2])) { |
|
| 1025 | + $valV = array($valV[0], $valV[0], $valV[1], $valV[1]); |
|
| 1026 | + } |
|
| 1027 | + if ( ! isset($valV[3])) { |
|
| 1028 | + $valV[3] = $valV[1]; |
|
| 1029 | + } |
|
| 946 | 1030 | } else { |
| 947 | 1031 | $valV = $valH; |
| 948 | 1032 | } |
@@ -1024,22 +1108,35 @@ discard block |
||
| 1024 | 1108 | break; |
| 1025 | 1109 | |
| 1026 | 1110 | case 'position': |
| 1027 | - if ($val == 'absolute') $this->value['position'] = 'absolute'; |
|
| 1028 | - else if ($val == 'relative') $this->value['position'] = 'relative'; |
|
| 1029 | - else $this->value['position'] = null; |
|
| 1111 | + if ($val == 'absolute') { |
|
| 1112 | + $this->value['position'] = 'absolute'; |
|
| 1113 | + } else if ($val == 'relative') { |
|
| 1114 | + $this->value['position'] = 'relative'; |
|
| 1115 | + } else { |
|
| 1116 | + $this->value['position'] = null; |
|
| 1117 | + } |
|
| 1030 | 1118 | break; |
| 1031 | 1119 | |
| 1032 | 1120 | case 'float': |
| 1033 | - if ($val == 'left') $this->value['float'] = 'left'; |
|
| 1034 | - else if ($val == 'right') $this->value['float'] = 'right'; |
|
| 1035 | - else $this->value['float'] = null; |
|
| 1121 | + if ($val == 'left') { |
|
| 1122 | + $this->value['float'] = 'left'; |
|
| 1123 | + } else if ($val == 'right') { |
|
| 1124 | + $this->value['float'] = 'right'; |
|
| 1125 | + } else { |
|
| 1126 | + $this->value['float'] = null; |
|
| 1127 | + } |
|
| 1036 | 1128 | break; |
| 1037 | 1129 | |
| 1038 | 1130 | case 'display': |
| 1039 | - if ($val == 'inline') $this->value['display'] = 'inline'; |
|
| 1040 | - else if ($val == 'block') $this->value['display'] = 'block'; |
|
| 1041 | - else if ($val == 'none') $this->value['display'] = 'none'; |
|
| 1042 | - else $this->value['display'] = null; |
|
| 1131 | + if ($val == 'inline') { |
|
| 1132 | + $this->value['display'] = 'inline'; |
|
| 1133 | + } else if ($val == 'block') { |
|
| 1134 | + $this->value['display'] = 'block'; |
|
| 1135 | + } else if ($val == 'none') { |
|
| 1136 | + $this->value['display'] = 'none'; |
|
| 1137 | + } else { |
|
| 1138 | + $this->value['display'] = null; |
|
| 1139 | + } |
|
| 1043 | 1140 | break; |
| 1044 | 1141 | |
| 1045 | 1142 | case 'top': |
@@ -1052,7 +1149,9 @@ discard block |
||
| 1052 | 1149 | case 'list-style': |
| 1053 | 1150 | case 'list-style-type': |
| 1054 | 1151 | case 'list-style-image': |
| 1055 | - if ($nom == 'list-style') $nom = 'list-style-type'; |
|
| 1152 | + if ($nom == 'list-style') { |
|
| 1153 | + $nom = 'list-style-type'; |
|
| 1154 | + } |
|
| 1056 | 1155 | $this->value[$nom] = $val; |
| 1057 | 1156 | break; |
| 1058 | 1157 | |
@@ -1064,11 +1163,17 @@ discard block |
||
| 1064 | 1163 | $return = true; |
| 1065 | 1164 | |
| 1066 | 1165 | // only for P tag |
| 1067 | - if ($this->value['margin']['t'] === null) $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1068 | - if ($this->value['margin']['b'] === null) $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1166 | + if ($this->value['margin']['t'] === null) { |
|
| 1167 | + $this->value['margin']['t'] = $this->value['font-size']; |
|
| 1168 | + } |
|
| 1169 | + if ($this->value['margin']['b'] === null) { |
|
| 1170 | + $this->value['margin']['b'] = $this->value['font-size']; |
|
| 1171 | + } |
|
| 1069 | 1172 | |
| 1070 | 1173 | // force the text align to left, if asked by html2pdf |
| 1071 | - if ($this->_onlyLeft) $this->value['text-align'] = 'left'; |
|
| 1174 | + if ($this->_onlyLeft) { |
|
| 1175 | + $this->value['text-align'] = 'left'; |
|
| 1176 | + } |
|
| 1072 | 1177 | |
| 1073 | 1178 | // correction on the width (quick box) |
| 1074 | 1179 | if ($noWidth && in_array($tagName, array('div', 'blockquote', 'fieldset')) && $this->value['position'] != 'absolute') { |
@@ -1084,30 +1189,60 @@ discard block |
||
| 1084 | 1189 | $this->value['width'] -= $this->convertToMM(isset($param['cellspacing']) ? $param['cellspacing'] : '2px'); |
| 1085 | 1190 | $return = false; |
| 1086 | 1191 | } |
| 1087 | - if ($this->value['width'] < 0) $this->value['width'] = 0; |
|
| 1192 | + if ($this->value['width'] < 0) { |
|
| 1193 | + $this->value['width'] = 0; |
|
| 1194 | + } |
|
| 1088 | 1195 | } else { |
| 1089 | 1196 | if ($this->value['width']) { |
| 1090 | - if ($this->value['border']['l']['width']) $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1091 | - if ($this->value['border']['r']['width']) $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1092 | - if ($this->value['padding']['l']) $this->value['width'] += $this->value['padding']['l']; |
|
| 1093 | - if ($this->value['padding']['r']) $this->value['width'] += $this->value['padding']['r']; |
|
| 1197 | + if ($this->value['border']['l']['width']) { |
|
| 1198 | + $this->value['width'] += $this->value['border']['l']['width']; |
|
| 1199 | + } |
|
| 1200 | + if ($this->value['border']['r']['width']) { |
|
| 1201 | + $this->value['width'] += $this->value['border']['r']['width']; |
|
| 1202 | + } |
|
| 1203 | + if ($this->value['padding']['l']) { |
|
| 1204 | + $this->value['width'] += $this->value['padding']['l']; |
|
| 1205 | + } |
|
| 1206 | + if ($this->value['padding']['r']) { |
|
| 1207 | + $this->value['width'] += $this->value['padding']['r']; |
|
| 1208 | + } |
|
| 1094 | 1209 | } |
| 1095 | 1210 | } |
| 1096 | 1211 | } |
| 1097 | 1212 | if ($this->value['height']) { |
| 1098 | - if ($this->value['border']['b']['width']) $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1099 | - if ($this->value['border']['t']['width']) $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1100 | - if ($this->value['padding']['b']) $this->value['height'] += $this->value['padding']['b']; |
|
| 1101 | - if ($this->value['padding']['t']) $this->value['height'] += $this->value['padding']['t']; |
|
| 1213 | + if ($this->value['border']['b']['width']) { |
|
| 1214 | + $this->value['height'] += $this->value['border']['b']['width']; |
|
| 1215 | + } |
|
| 1216 | + if ($this->value['border']['t']['width']) { |
|
| 1217 | + $this->value['height'] += $this->value['border']['t']['width']; |
|
| 1218 | + } |
|
| 1219 | + if ($this->value['padding']['b']) { |
|
| 1220 | + $this->value['height'] += $this->value['padding']['b']; |
|
| 1221 | + } |
|
| 1222 | + if ($this->value['padding']['t']) { |
|
| 1223 | + $this->value['height'] += $this->value['padding']['t']; |
|
| 1224 | + } |
|
| 1102 | 1225 | } |
| 1103 | 1226 | |
| 1104 | - if ($this->value['top'] != null) $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1105 | - if ($this->value['bottom'] != null) $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1106 | - if ($this->value['left'] != null) $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1107 | - if ($this->value['right'] != null) $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1227 | + if ($this->value['top'] != null) { |
|
| 1228 | + $this->value['top'] = $this->convertToMM($this->value['top'], $this->getLastHeight(true)); |
|
| 1229 | + } |
|
| 1230 | + if ($this->value['bottom'] != null) { |
|
| 1231 | + $this->value['bottom'] = $this->convertToMM($this->value['bottom'], $this->getLastHeight(true)); |
|
| 1232 | + } |
|
| 1233 | + if ($this->value['left'] != null) { |
|
| 1234 | + $this->value['left'] = $this->convertToMM($this->value['left'], $this->getLastWidth(true)); |
|
| 1235 | + } |
|
| 1236 | + if ($this->value['right'] != null) { |
|
| 1237 | + $this->value['right'] = $this->convertToMM($this->value['right'], $this->getLastWidth(true)); |
|
| 1238 | + } |
|
| 1108 | 1239 | |
| 1109 | - if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) $this->value['bottom'] = null; |
|
| 1110 | - if ($this->value['left'] && $this->value['right'] && $this->value['width']) $this->value['right'] = null; |
|
| 1240 | + if ($this->value['top'] && $this->value['bottom'] && $this->value['height']) { |
|
| 1241 | + $this->value['bottom'] = null; |
|
| 1242 | + } |
|
| 1243 | + if ($this->value['left'] && $this->value['right'] && $this->value['width']) { |
|
| 1244 | + $this->value['right'] = null; |
|
| 1245 | + } |
|
| 1111 | 1246 | |
| 1112 | 1247 | return $return; |
| 1113 | 1248 | } |
@@ -1121,7 +1256,9 @@ discard block |
||
| 1121 | 1256 | public function getLineHeight() |
| 1122 | 1257 | { |
| 1123 | 1258 | $val = $this->value['line-height']; |
| 1124 | - if ($val == 'normal') $val = '108%'; |
|
| 1259 | + if ($val == 'normal') { |
|
| 1260 | + $val = '108%'; |
|
| 1261 | + } |
|
| 1125 | 1262 | return $this->convertToMM($val, $this->value['font-size']); |
| 1126 | 1263 | } |
| 1127 | 1264 | |
@@ -1177,8 +1314,12 @@ discard block |
||
| 1177 | 1314 | */ |
| 1178 | 1315 | public function getFloat() |
| 1179 | 1316 | { |
| 1180 | - if ($this->value['float'] == 'left') return 'left'; |
|
| 1181 | - if ($this->value['float'] == 'right') return 'right'; |
|
| 1317 | + if ($this->value['float'] == 'left') { |
|
| 1318 | + return 'left'; |
|
| 1319 | + } |
|
| 1320 | + if ($this->value['float'] == 'right') { |
|
| 1321 | + return 'right'; |
|
| 1322 | + } |
|
| 1182 | 1323 | return null; |
| 1183 | 1324 | } |
| 1184 | 1325 | |
@@ -1208,7 +1349,9 @@ discard block |
||
| 1208 | 1349 | protected function _getLastAbsoluteX() |
| 1209 | 1350 | { |
| 1210 | 1351 | for ($k = count($this->table) - 1; $k >= 0; $k--) { |
| 1211 | - if ($this->table[$k]['x'] && $this->table[$k]['position']) return $this->table[$k]['x']; |
|
| 1352 | + if ($this->table[$k]['x'] && $this->table[$k]['position']) { |
|
| 1353 | + return $this->table[$k]['x']; |
|
| 1354 | + } |
|
| 1212 | 1355 | } |
| 1213 | 1356 | return $this->_pdf->getlMargin(); |
| 1214 | 1357 | } |
@@ -1222,7 +1365,9 @@ discard block |
||
| 1222 | 1365 | protected function _getLastAbsoluteY() |
| 1223 | 1366 | { |
| 1224 | 1367 | for ($k = count($this->table) - 1; $k >= 0; $k--) { |
| 1225 | - if ($this->table[$k]['y'] && $this->table[$k]['position']) return $this->table[$k]['y']; |
|
| 1368 | + if ($this->table[$k]['y'] && $this->table[$k]['position']) { |
|
| 1369 | + return $this->table[$k]['y']; |
|
| 1370 | + } |
|
| 1226 | 1371 | } |
| 1227 | 1372 | return $this->_pdf->gettMargin(); |
| 1228 | 1373 | } |
@@ -1364,12 +1509,16 @@ discard block |
||
| 1364 | 1509 | // else, it could be the color |
| 1365 | 1510 | } else { |
| 1366 | 1511 | $tmp = $this->convertToColor($value, $res); |
| 1367 | - if ($res) $color = $tmp; |
|
| 1512 | + if ($res) { |
|
| 1513 | + $color = $tmp; |
|
| 1514 | + } |
|
| 1368 | 1515 | } |
| 1369 | 1516 | } |
| 1370 | 1517 | |
| 1371 | 1518 | // if no witdh => return none |
| 1372 | - if ( ! $width) return $none; |
|
| 1519 | + if ( ! $width) { |
|
| 1520 | + return $none; |
|
| 1521 | + } |
|
| 1373 | 1522 | |
| 1374 | 1523 | // return the border properties |
| 1375 | 1524 | return array('type' => $type, 'width' => $width, 'color' => $color); |
@@ -1474,8 +1623,11 @@ discard block |
||
| 1474 | 1623 | public function convertBackgroundColor($css) |
| 1475 | 1624 | { |
| 1476 | 1625 | $res = null; |
| 1477 | - if ($css == 'transparent') return null; |
|
| 1478 | - else return $this->convertToColor($css, $res); |
|
| 1626 | + if ($css == 'transparent') { |
|
| 1627 | + return null; |
|
| 1628 | + } else { |
|
| 1629 | + return $this->convertToColor($css, $res); |
|
| 1630 | + } |
|
| 1479 | 1631 | } |
| 1480 | 1632 | |
| 1481 | 1633 | /** |
@@ -1487,12 +1639,13 @@ discard block |
||
| 1487 | 1639 | */ |
| 1488 | 1640 | public function convertBackgroundImage($css) |
| 1489 | 1641 | { |
| 1490 | - if ($css == 'none') |
|
| 1491 | - return null; |
|
| 1492 | - else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) |
|
| 1493 | - return $match[1]; |
|
| 1494 | - else |
|
| 1495 | - return null; |
|
| 1642 | + if ($css == 'none') { |
|
| 1643 | + return null; |
|
| 1644 | + } else if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) { |
|
| 1645 | + return $match[1]; |
|
| 1646 | + } else { |
|
| 1647 | + return null; |
|
| 1648 | + } |
|
| 1496 | 1649 | } |
| 1497 | 1650 | |
| 1498 | 1651 | /** |
@@ -1513,10 +1666,14 @@ discard block |
||
| 1513 | 1666 | |
| 1514 | 1667 | // we must have 2 values. if 0 or >2 : error. if 1 => put center for 2 |
| 1515 | 1668 | if (count($css) < 2) { |
| 1516 | - if ( ! $css[0]) return null; |
|
| 1669 | + if ( ! $css[0]) { |
|
| 1670 | + return null; |
|
| 1671 | + } |
|
| 1517 | 1672 | $css[1] = 'center'; |
| 1518 | 1673 | } |
| 1519 | - if (count($css) > 2) return null; |
|
| 1674 | + if (count($css) > 2) { |
|
| 1675 | + return null; |
|
| 1676 | + } |
|
| 1520 | 1677 | |
| 1521 | 1678 | // prepare the values |
| 1522 | 1679 | $x = 0; |
@@ -1524,24 +1681,42 @@ discard block |
||
| 1524 | 1681 | $res = true; |
| 1525 | 1682 | |
| 1526 | 1683 | // convert the first value |
| 1527 | - if ($css[0] == 'left') $x = '0%'; |
|
| 1528 | - else if ($css[0] == 'center') $x = '50%'; |
|
| 1529 | - else if ($css[0] == 'right') $x = '100%'; |
|
| 1530 | - else if ($css[0] == 'top') $y = '0%'; |
|
| 1531 | - else if ($css[0] == 'bottom') $y = '100%'; |
|
| 1532 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) $x = $css[0]; |
|
| 1533 | - else if ($this->convertToMM($css[0])) $x = $this->convertToMM($css[0]); |
|
| 1534 | - else $res = false; |
|
| 1684 | + if ($css[0] == 'left') { |
|
| 1685 | + $x = '0%'; |
|
| 1686 | + } else if ($css[0] == 'center') { |
|
| 1687 | + $x = '50%'; |
|
| 1688 | + } else if ($css[0] == 'right') { |
|
| 1689 | + $x = '100%'; |
|
| 1690 | + } else if ($css[0] == 'top') { |
|
| 1691 | + $y = '0%'; |
|
| 1692 | + } else if ($css[0] == 'bottom') { |
|
| 1693 | + $y = '100%'; |
|
| 1694 | + } else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) { |
|
| 1695 | + $x = $css[0]; |
|
| 1696 | + } else if ($this->convertToMM($css[0])) { |
|
| 1697 | + $x = $this->convertToMM($css[0]); |
|
| 1698 | + } else { |
|
| 1699 | + $res = false; |
|
| 1700 | + } |
|
| 1535 | 1701 | |
| 1536 | 1702 | // convert the second value |
| 1537 | - if ($css[1] == 'left') $x = '0%'; |
|
| 1538 | - else if ($css[1] == 'right') $x = '100%'; |
|
| 1539 | - else if ($css[1] == 'top') $y = '0%'; |
|
| 1540 | - else if ($css[1] == 'center') $y = '50%'; |
|
| 1541 | - else if ($css[1] == 'bottom') $y = '100%'; |
|
| 1542 | - else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) $y = $css[1]; |
|
| 1543 | - else if ($this->convertToMM($css[1])) $y = $this->convertToMM($css[1]); |
|
| 1544 | - else $res = false; |
|
| 1703 | + if ($css[1] == 'left') { |
|
| 1704 | + $x = '0%'; |
|
| 1705 | + } else if ($css[1] == 'right') { |
|
| 1706 | + $x = '100%'; |
|
| 1707 | + } else if ($css[1] == 'top') { |
|
| 1708 | + $y = '0%'; |
|
| 1709 | + } else if ($css[1] == 'center') { |
|
| 1710 | + $y = '50%'; |
|
| 1711 | + } else if ($css[1] == 'bottom') { |
|
| 1712 | + $y = '100%'; |
|
| 1713 | + } else if (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) { |
|
| 1714 | + $y = $css[1]; |
|
| 1715 | + } else if ($this->convertToMM($css[1])) { |
|
| 1716 | + $y = $this->convertToMM($css[1]); |
|
| 1717 | + } else { |
|
| 1718 | + $res = false; |
|
| 1719 | + } |
|
| 1545 | 1720 | |
| 1546 | 1721 | // return the values |
| 1547 | 1722 | return array($x, $y); |
@@ -1581,13 +1756,22 @@ discard block |
||
| 1581 | 1756 | public function convertToMM($css, $old = 0.) |
| 1582 | 1757 | { |
| 1583 | 1758 | $css = trim($css); |
| 1584 | - if (preg_match('/^[0-9\.\-]+$/isU', $css)) $css .= 'px'; |
|
| 1585 | - if (preg_match('/^[0-9\.\-]+px$/isU', $css)) $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1586 | - else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1587 | - else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) $css = 25.4 * str_replace('in', '', $css); |
|
| 1588 | - else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) $css = 1. * str_replace('mm', '', $css); |
|
| 1589 | - else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1590 | - else $css = null; |
|
| 1759 | + if (preg_match('/^[0-9\.\-]+$/isU', $css)) { |
|
| 1760 | + $css .= 'px'; |
|
| 1761 | + } |
|
| 1762 | + if (preg_match('/^[0-9\.\-]+px$/isU', $css)) { |
|
| 1763 | + $css = 25.4 / 96. * str_replace('px', '', $css); |
|
| 1764 | + } else if (preg_match('/^[0-9\.\-]+pt$/isU', $css)) { |
|
| 1765 | + $css = 25.4 / 72. * str_replace('pt', '', $css); |
|
| 1766 | + } else if (preg_match('/^[0-9\.\-]+in$/isU', $css)) { |
|
| 1767 | + $css = 25.4 * str_replace('in', '', $css); |
|
| 1768 | + } else if (preg_match('/^[0-9\.\-]+mm$/isU', $css)) { |
|
| 1769 | + $css = 1. * str_replace('mm', '', $css); |
|
| 1770 | + } else if (preg_match('/^[0-9\.\-]+%$/isU', $css)) { |
|
| 1771 | + $css = 1. * $old * str_replace('%', '', $css) / 100.; |
|
| 1772 | + } else { |
|
| 1773 | + $css = null; |
|
| 1774 | + } |
|
| 1591 | 1775 | |
| 1592 | 1776 | return $css; |
| 1593 | 1777 | } |
@@ -1636,7 +1820,9 @@ discard block |
||
| 1636 | 1820 | $res = true; |
| 1637 | 1821 | |
| 1638 | 1822 | // if transparent => return null |
| 1639 | - if (strtolower($css) == 'transparent') return array(null, null, null); |
|
| 1823 | + if (strtolower($css) == 'transparent') { |
|
| 1824 | + return array(null, null, null); |
|
| 1825 | + } |
|
| 1640 | 1826 | |
| 1641 | 1827 | // HTML color |
| 1642 | 1828 | if (isset($this->_htmlColor[strtolower($css)])) { |
@@ -1697,7 +1883,9 @@ discard block |
||
| 1697 | 1883 | $c = floatVal(substr($c, 0, -1)) / 100.; |
| 1698 | 1884 | } else { |
| 1699 | 1885 | $c = floatVal($c); |
| 1700 | - if ($c > 1) $c = $c / 255.; |
|
| 1886 | + if ($c > 1) { |
|
| 1887 | + $c = $c / 255.; |
|
| 1888 | + } |
|
| 1701 | 1889 | } |
| 1702 | 1890 | |
| 1703 | 1891 | return $c; |
@@ -1751,13 +1939,16 @@ discard block |
||
| 1751 | 1939 | $name = trim($name); |
| 1752 | 1940 | |
| 1753 | 1941 | // if a selector with somethink lige :hover => continue |
| 1754 | - if (strpos($name, ':') !== false) continue; |
|
| 1942 | + if (strpos($name, ':') !== false) { |
|
| 1943 | + continue; |
|
| 1944 | + } |
|
| 1755 | 1945 | |
| 1756 | 1946 | // save the value |
| 1757 | - if ( ! isset($this->css[$name])) |
|
| 1758 | - $this->css[$name] = $css; |
|
| 1759 | - else |
|
| 1760 | - $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1947 | + if ( ! isset($this->css[$name])) { |
|
| 1948 | + $this->css[$name] = $css; |
|
| 1949 | + } else { |
|
| 1950 | + $this->css[$name] = array_merge($this->css[$name], $css); |
|
| 1951 | + } |
|
| 1761 | 1952 | |
| 1762 | 1953 | } |
| 1763 | 1954 | } |
@@ -50,6 +50,7 @@ |
||
| 50 | 50 | * Define the HTML code to parse |
| 51 | 51 | * |
| 52 | 52 | * @param string HTML code |
| 53 | + * @param string $html |
|
| 53 | 54 | * @access public |
| 54 | 55 | */ |
| 55 | 56 | public function setHTML($html) |
@@ -11,524 +11,524 @@ |
||
| 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 | - * @param string $encoding |
|
| 42 | - * @access public |
|
| 43 | - */ |
|
| 44 | - public function setEncoding($encoding) |
|
| 45 | - { |
|
| 46 | - $this->_encoding = $encoding; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Define the HTML code to parse |
|
| 51 | - * |
|
| 52 | - * @param string HTML code |
|
| 53 | - * @access public |
|
| 54 | - */ |
|
| 55 | - public function setHTML($html) |
|
| 56 | - { |
|
| 57 | - // remove the HTML in comment |
|
| 58 | - $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
| 59 | - |
|
| 60 | - // save the HTML code |
|
| 61 | - $this->_html = $html; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * parse the HTML code |
|
| 66 | - * |
|
| 67 | - * @access public |
|
| 68 | - */ |
|
| 69 | - public function parse() |
|
| 70 | - { |
|
| 71 | - $parents = array(); |
|
| 72 | - |
|
| 73 | - // flag : are we in a <pre> Tag ? |
|
| 74 | - $tagPreIn = false; |
|
| 75 | - |
|
| 76 | - // action to use for each line of the content of a <pre> Tag |
|
| 77 | - $tagPreBr = array( |
|
| 78 | - 'name' => 'br', |
|
| 79 | - 'close' => false, |
|
| 80 | - 'param' => array( |
|
| 81 | - 'style' => array(), |
|
| 82 | - 'num' => 0 |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - // tag that can be not closed |
|
| 87 | - $tagsNotClosed = array( |
|
| 88 | - 'br', 'hr', 'img', 'col', |
|
| 89 | - 'input', 'link', 'option', |
|
| 90 | - 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // search the HTML tags |
|
| 94 | - $tmp = array(); |
|
| 95 | - $this->_searchCode($tmp); |
|
| 96 | - |
|
| 97 | - // all the actions to do |
|
| 98 | - $actions = array(); |
|
| 99 | - |
|
| 100 | - // foreach part of the HTML code |
|
| 101 | - foreach ($tmp as $part) { |
|
| 102 | - // if it is a tag code |
|
| 103 | - if ($part[0] == 'code') { |
|
| 104 | - // analise the HTML code |
|
| 105 | - $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 | + * @param string $encoding |
|
| 42 | + * @access public |
|
| 43 | + */ |
|
| 44 | + public function setEncoding($encoding) |
|
| 45 | + { |
|
| 46 | + $this->_encoding = $encoding; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Define the HTML code to parse |
|
| 51 | + * |
|
| 52 | + * @param string HTML code |
|
| 53 | + * @access public |
|
| 54 | + */ |
|
| 55 | + public function setHTML($html) |
|
| 56 | + { |
|
| 57 | + // remove the HTML in comment |
|
| 58 | + $html = preg_replace('/<!--(.*)-->/isU', '', $html); |
|
| 59 | + |
|
| 60 | + // save the HTML code |
|
| 61 | + $this->_html = $html; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * parse the HTML code |
|
| 66 | + * |
|
| 67 | + * @access public |
|
| 68 | + */ |
|
| 69 | + public function parse() |
|
| 70 | + { |
|
| 71 | + $parents = array(); |
|
| 72 | + |
|
| 73 | + // flag : are we in a <pre> Tag ? |
|
| 74 | + $tagPreIn = false; |
|
| 75 | + |
|
| 76 | + // action to use for each line of the content of a <pre> Tag |
|
| 77 | + $tagPreBr = array( |
|
| 78 | + 'name' => 'br', |
|
| 79 | + 'close' => false, |
|
| 80 | + 'param' => array( |
|
| 81 | + 'style' => array(), |
|
| 82 | + 'num' => 0 |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + // tag that can be not closed |
|
| 87 | + $tagsNotClosed = array( |
|
| 88 | + 'br', 'hr', 'img', 'col', |
|
| 89 | + 'input', 'link', 'option', |
|
| 90 | + 'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline' |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // search the HTML tags |
|
| 94 | + $tmp = array(); |
|
| 95 | + $this->_searchCode($tmp); |
|
| 96 | + |
|
| 97 | + // all the actions to do |
|
| 98 | + $actions = array(); |
|
| 99 | + |
|
| 100 | + // foreach part of the HTML code |
|
| 101 | + foreach ($tmp as $part) { |
|
| 102 | + // if it is a tag code |
|
| 103 | + if ($part[0] == 'code') { |
|
| 104 | + // analise the HTML code |
|
| 105 | + $res = $this->_analiseCode($part[1]); |
|
| 106 | 106 | |
| 107 | 107 | //echo "<pre>"; print_r($tagsNotClosed); exit; |
| 108 | - // if it is a real HTML tag |
|
| 109 | - if ($res) { |
|
| 110 | - // save the current posistion in the HTML code |
|
| 111 | - $res['html_pos'] = $part[2]; |
|
| 112 | - |
|
| 113 | - // if the tag must be closed |
|
| 114 | - if ( ! in_array($res['name'], $tagsNotClosed)) { |
|
| 115 | - // if it is a closure tag |
|
| 116 | - if ($res['close']) { |
|
| 117 | - // HTML validation |
|
| 118 | - if (count($parents) < 1) |
|
| 119 | - throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | - else if ($parents[count($parents) - 1] != $res['name']) |
|
| 121 | - throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | - else |
|
| 123 | - unset($parents[count($parents) - 1]); |
|
| 124 | - } else { |
|
| 125 | - // if it is a autoclosed tag |
|
| 126 | - if ($res['autoclose']) { |
|
| 127 | - // save the opened tag |
|
| 128 | - $actions[] = $res; |
|
| 129 | - |
|
| 130 | - // prepare the closed tag |
|
| 131 | - $res['params'] = array(); |
|
| 132 | - $res['close'] = true; |
|
| 133 | - } |
|
| 134 | - // else :add a child for validation |
|
| 135 | - else { |
|
| 136 | - $parents[count($parents)] = $res['name']; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
| 141 | - if (($res['name'] == 'pre' || $res['name'] == 'code') && ! $res['autoclose']) { |
|
| 142 | - $tagPreIn = ! $res['close']; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // save the actions to convert |
|
| 147 | - $actions[] = $res; |
|
| 148 | - } else { // else (it is not a real HTML tag => we transform it in Texte |
|
| 149 | - $part[0] = 'txt'; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - // if it is text |
|
| 153 | - if ($part[0] == 'txt') { |
|
| 154 | - // if we are not in a <pre> tag |
|
| 155 | - if ( ! $tagPreIn) { |
|
| 156 | - // save the action |
|
| 157 | - $actions[] = array( |
|
| 158 | - 'name' => 'write', |
|
| 159 | - 'close' => false, |
|
| 160 | - 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
| 161 | - ); |
|
| 162 | - } else { // else (if we are in a <pre> tag) |
|
| 163 | - // prepare the text |
|
| 164 | - $part[1] = str_replace("\r", '', $part[1]); |
|
| 165 | - $part[1] = explode("\n", $part[1]); |
|
| 166 | - |
|
| 167 | - // foreach line of the text |
|
| 168 | - foreach ($part[1] as $k => $txt) { |
|
| 169 | - // transform the line |
|
| 170 | - $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
| 171 | - $txt = str_replace(' ', ' ', $txt); |
|
| 172 | - |
|
| 173 | - // add a break line |
|
| 174 | - if ($k > 0) $actions[] = $tagPreBr; |
|
| 175 | - |
|
| 176 | - // save the action |
|
| 177 | - $actions[] = array( |
|
| 178 | - 'name' => 'write', |
|
| 179 | - 'close' => false, |
|
| 180 | - 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // for each indentified action, we have to clean up the begin and the end of the texte |
|
| 188 | - // based on tags that surround it |
|
| 189 | - |
|
| 190 | - // list of the tags to clean |
|
| 191 | - $tagsToClean = array( |
|
| 192 | - 'page', 'page_header', 'page_footer', 'form', |
|
| 193 | - 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
| 194 | - 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
| 195 | - 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
| 196 | - 'bookmark', 'fieldset', 'legend', |
|
| 197 | - 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
| 198 | - 'option' |
|
| 199 | - ); |
|
| 200 | - |
|
| 201 | - // foreach action |
|
| 202 | - $nb = count($actions); |
|
| 203 | - for ($k = 0; $k < $nb; $k++) { |
|
| 204 | - // if it is a Text |
|
| 205 | - if ($actions[$k]['name'] == 'write') { |
|
| 206 | - // if the tag before the text is a tag to clean => ltrim on the text |
|
| 207 | - if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) |
|
| 208 | - $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 209 | - |
|
| 210 | - // if the tag after the text is a tag to clean => rtrim on the text |
|
| 211 | - if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) |
|
| 212 | - $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 213 | - |
|
| 214 | - // if the text is empty => remove the action |
|
| 215 | - if ( ! strlen($actions[$k]['param']['txt'])) |
|
| 216 | - unset($actions[$k]); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // if we are not on the level 0 => HTML validator ERROR |
|
| 221 | - if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
| 222 | - |
|
| 223 | - // save the actions to do |
|
| 224 | - $this->code = array_values($actions); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * prepare the text |
|
| 229 | - * |
|
| 230 | - * @param string texte |
|
| 231 | - * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
| 232 | - * @return string texte |
|
| 233 | - * @access protected |
|
| 234 | - */ |
|
| 235 | - protected function _prepareTxt($txt, $spaces = true) |
|
| 236 | - { |
|
| 237 | - if ($spaces) { |
|
| 238 | - $txt = preg_replace('/\s+/is', ' ', $txt); |
|
| 239 | - } |
|
| 240 | - $txt = str_replace('€', '€', $txt); |
|
| 241 | - $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
| 242 | - return $txt; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * parse the HTML code |
|
| 247 | - * |
|
| 248 | - * @param &array array's result |
|
| 249 | - * @return null |
|
| 250 | - */ |
|
| 251 | - protected function _searchCode(&$tmp) |
|
| 252 | - { |
|
| 253 | - // initialise the array |
|
| 254 | - $tmp = array(); |
|
| 255 | - |
|
| 256 | - // regexp to separate the tags from the texts |
|
| 257 | - $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
| 258 | - |
|
| 259 | - // last match found |
|
| 260 | - $str = ''; |
|
| 261 | - $offset = 0; |
|
| 262 | - |
|
| 263 | - // As it finds a match |
|
| 264 | - while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
| 265 | - // if it is a tag |
|
| 266 | - if ($parse[1][0]) { |
|
| 267 | - // save the previous text if it exists |
|
| 268 | - if ($str !== '') $tmp[] = array('txt', $str); |
|
| 269 | - |
|
| 270 | - // save the tag, with the offset |
|
| 271 | - $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
| 272 | - |
|
| 273 | - // init the current text |
|
| 274 | - $str = ''; |
|
| 275 | - } else { // else (if it is a text) |
|
| 276 | - // add the new text to the current text |
|
| 277 | - $str .= $parse[2][0]; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // Update offset to the end of the match |
|
| 281 | - $offset = $parse[0][1] + strlen($parse[0][0]); |
|
| 282 | - unset($parse); |
|
| 283 | - } |
|
| 284 | - // if a text is present in the end, we save it |
|
| 285 | - if ($str != '') $tmp[] = array('txt', $str); |
|
| 286 | - unset($str); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * analise a HTML tag |
|
| 291 | - * |
|
| 292 | - * @param string HTML code to analise |
|
| 293 | - * @return array corresponding action |
|
| 294 | - */ |
|
| 295 | - protected function _analiseCode($code) |
|
| 296 | - { |
|
| 297 | - // name of the tag, opening, closure, autoclosure |
|
| 298 | - $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
| 299 | - if ( ! preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
| 300 | - $close = ($match[1] == '/' ? true : false); |
|
| 301 | - $autoclose = preg_match('/\/>$/isU', $code); |
|
| 302 | - $name = strtolower($match[2]); |
|
| 303 | - |
|
| 304 | - // required parameters (depends on the tag name) |
|
| 305 | - $param = array(); |
|
| 306 | - $param['style'] = ''; |
|
| 307 | - if ($name == 'img') { |
|
| 308 | - $param['alt'] = ''; |
|
| 309 | - $param['src'] = ''; |
|
| 310 | - } |
|
| 311 | - if ($name == 'a') { |
|
| 312 | - $param['href'] = ''; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // read the parameters : nom=valeur |
|
| 316 | - $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 317 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 318 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 319 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 320 | - |
|
| 321 | - // read the parameters : nom="valeur" |
|
| 322 | - $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 323 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 324 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 325 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 326 | - |
|
| 327 | - // read the parameters : nom='valeur' |
|
| 328 | - $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 329 | - preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 330 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 331 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 332 | - |
|
| 333 | - // compliance of each parameter |
|
| 334 | - $color = "#000000"; |
|
| 335 | - $border = null; |
|
| 336 | - foreach ($param as $key => $val) { |
|
| 337 | - $key = strtolower($key); |
|
| 338 | - switch ($key) |
|
| 339 | - { |
|
| 340 | - case 'width': |
|
| 341 | - unset($param[$key]); |
|
| 342 | - $param['style'] .= 'width: '.$val.'px; '; |
|
| 343 | - break; |
|
| 344 | - |
|
| 345 | - case 'align': |
|
| 346 | - if ($name === 'img') { |
|
| 347 | - unset($param[$key]); |
|
| 348 | - $param['style'] .= 'float: '.$val.'; '; |
|
| 349 | - } elseif ($name !== 'table') { |
|
| 350 | - unset($param[$key]); |
|
| 351 | - $param['style'] .= 'text-align: '.$val.'; '; |
|
| 352 | - } |
|
| 353 | - break; |
|
| 354 | - |
|
| 355 | - case 'valign': |
|
| 356 | - unset($param[$key]); |
|
| 357 | - $param['style'] .= 'vertical-align: '.$val.'; '; |
|
| 358 | - break; |
|
| 359 | - |
|
| 360 | - case 'height': |
|
| 361 | - unset($param[$key]); |
|
| 362 | - $param['style'] .= 'height: '.$val.'px; '; |
|
| 363 | - break; |
|
| 364 | - |
|
| 365 | - case 'bgcolor': |
|
| 366 | - unset($param[$key]); |
|
| 367 | - $param['style'] .= 'background: '.$val.'; '; |
|
| 368 | - break; |
|
| 369 | - |
|
| 370 | - case 'bordercolor': |
|
| 371 | - unset($param[$key]); |
|
| 372 | - $color = $val; |
|
| 373 | - break; |
|
| 374 | - |
|
| 375 | - case 'border': |
|
| 376 | - unset($param[$key]); |
|
| 377 | - if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
| 378 | - $border = $val; |
|
| 379 | - break; |
|
| 380 | - |
|
| 381 | - case 'cellpadding': |
|
| 382 | - case 'cellspacing': |
|
| 383 | - if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
| 384 | - break; |
|
| 385 | - |
|
| 386 | - case 'colspan': |
|
| 387 | - case 'rowspan': |
|
| 388 | - $val = preg_replace('/[^0-9]/isU', '', $val); |
|
| 389 | - if ( ! $val) $val = 1; |
|
| 390 | - $param[$key] = $val; |
|
| 391 | - break; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - // compliance of the border |
|
| 396 | - if ($border !== null) { |
|
| 397 | - if ($border) $border = 'border: solid '.$border.' '.$color; |
|
| 398 | - else $border = 'border: none'; |
|
| 399 | - |
|
| 400 | - $param['style'] .= $border.'; '; |
|
| 401 | - $param['border'] = $border; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // reading styles: decomposition and standardization |
|
| 405 | - $styles = explode(';', $param['style']); |
|
| 406 | - $param['style'] = array(); |
|
| 407 | - foreach ($styles as $style) { |
|
| 408 | - $tmp = explode(':', $style); |
|
| 409 | - if (count($tmp) > 1) { |
|
| 410 | - $cod = $tmp[0]; |
|
| 411 | - unset($tmp[0]); |
|
| 412 | - $tmp = implode(':', $tmp); |
|
| 413 | - $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // determining the level of table opening, with an added level |
|
| 418 | - if (in_array($name, array('ul', 'ol', 'table')) && ! $close) { |
|
| 419 | - $this->_num++; |
|
| 420 | - $this->_level[count($this->_level)] = $this->_num; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - // get the level of the table containing the element |
|
| 424 | - if ( ! isset($param['num'])) { |
|
| 425 | - $param['num'] = $this->_level[count($this->_level) - 1]; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // for closures table: remove a level |
|
| 429 | - if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
| 430 | - unset($this->_level[count($this->_level) - 1]); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // prepare the parameters |
|
| 434 | - if (isset($param['value'])) { |
|
| 435 | - $param['value'] = $this->_prepareTxt($param['value']); |
|
| 436 | - } |
|
| 437 | - if (isset($param['alt'])) { |
|
| 438 | - $param['alt'] = $this->_prepareTxt($param['alt']); |
|
| 439 | - } |
|
| 440 | - if (isset($param['title'])) { |
|
| 441 | - $param['title'] = $this->_prepareTxt($param['title']); |
|
| 442 | - } |
|
| 443 | - if (isset($param['class'])) { |
|
| 444 | - $param['class'] = $this->_prepareTxt($param['class']); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // return the new action to do |
|
| 448 | - return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * get a full level of HTML, between an opening and closing corresponding |
|
| 453 | - * |
|
| 454 | - * @param integer key |
|
| 455 | - * @param integer $k |
|
| 456 | - * @return array actions |
|
| 457 | - */ |
|
| 458 | - public function getLevel($k) |
|
| 459 | - { |
|
| 460 | - // if the code does not exist => return empty |
|
| 461 | - if ( ! isset($this->code[$k])) return array(); |
|
| 462 | - |
|
| 463 | - // the tag to detect |
|
| 464 | - $detect = $this->code[$k]['name']; |
|
| 465 | - |
|
| 466 | - // if it is a text => return |
|
| 467 | - if ($detect == 'write') { |
|
| 468 | - return array($this->code[$k]); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - // |
|
| 472 | - $level = 0; // depth level |
|
| 473 | - $end = false; // end of the search |
|
| 474 | - $code = array(); // extract code |
|
| 475 | - |
|
| 476 | - // while it's not ended |
|
| 477 | - while ( ! $end) { |
|
| 478 | - // current action |
|
| 479 | - $row = $this->code[$k]; |
|
| 480 | - |
|
| 481 | - // if 'write' => we add the text |
|
| 482 | - if ($row['name'] == 'write') { |
|
| 483 | - $code[] = $row; |
|
| 484 | - } else { // else, it is a html tag |
|
| 485 | - $not = false; // flag for not taking into account the current tag |
|
| 486 | - |
|
| 487 | - // if it is the searched tag |
|
| 488 | - if ($row['name'] == $detect) { |
|
| 489 | - // if we are just at the root level => dont take it |
|
| 490 | - if ($level == 0) { |
|
| 491 | - $not = true; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // update the level |
|
| 495 | - $level += ($row['close'] ? -1 : 1); |
|
| 496 | - |
|
| 497 | - // if we are now at the root level => it is the end, and dont take it |
|
| 498 | - if ($level == 0) { |
|
| 499 | - $not = true; |
|
| 500 | - $end = true; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - // if we can takin into account the current tag => save it |
|
| 505 | - if ( ! $not) { |
|
| 506 | - if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
| 507 | - $code[] = $row; |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - // it continues as long as there has code to analise |
|
| 512 | - if (isset($this->code[$k + 1])) |
|
| 513 | - $k++; |
|
| 514 | - else |
|
| 515 | - $end = true; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - // return the extract |
|
| 519 | - return $code; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * return a part of the HTML code, for error message |
|
| 524 | - * |
|
| 525 | - * @param integer position |
|
| 526 | - * @param integer take before |
|
| 527 | - * @param integer take after |
|
| 528 | - * @return string part of the html code |
|
| 529 | - */ |
|
| 530 | - public function getHtmlErrorCode($pos, $before = 30, $after = 40) |
|
| 531 | - { |
|
| 532 | - return substr($this->_html, $pos - $before, $before + $after); |
|
| 533 | - } |
|
| 108 | + // if it is a real HTML tag |
|
| 109 | + if ($res) { |
|
| 110 | + // save the current posistion in the HTML code |
|
| 111 | + $res['html_pos'] = $part[2]; |
|
| 112 | + |
|
| 113 | + // if the tag must be closed |
|
| 114 | + if ( ! in_array($res['name'], $tagsNotClosed)) { |
|
| 115 | + // if it is a closure tag |
|
| 116 | + if ($res['close']) { |
|
| 117 | + // HTML validation |
|
| 118 | + if (count($parents) < 1) |
|
| 119 | + throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | + else if ($parents[count($parents) - 1] != $res['name']) |
|
| 121 | + throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | + else |
|
| 123 | + unset($parents[count($parents) - 1]); |
|
| 124 | + } else { |
|
| 125 | + // if it is a autoclosed tag |
|
| 126 | + if ($res['autoclose']) { |
|
| 127 | + // save the opened tag |
|
| 128 | + $actions[] = $res; |
|
| 129 | + |
|
| 130 | + // prepare the closed tag |
|
| 131 | + $res['params'] = array(); |
|
| 132 | + $res['close'] = true; |
|
| 133 | + } |
|
| 134 | + // else :add a child for validation |
|
| 135 | + else { |
|
| 136 | + $parents[count($parents)] = $res['name']; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // if it is a <pre> tag (or <code> tag) not auclosed => update the flag |
|
| 141 | + if (($res['name'] == 'pre' || $res['name'] == 'code') && ! $res['autoclose']) { |
|
| 142 | + $tagPreIn = ! $res['close']; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // save the actions to convert |
|
| 147 | + $actions[] = $res; |
|
| 148 | + } else { // else (it is not a real HTML tag => we transform it in Texte |
|
| 149 | + $part[0] = 'txt'; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + // if it is text |
|
| 153 | + if ($part[0] == 'txt') { |
|
| 154 | + // if we are not in a <pre> tag |
|
| 155 | + if ( ! $tagPreIn) { |
|
| 156 | + // save the action |
|
| 157 | + $actions[] = array( |
|
| 158 | + 'name' => 'write', |
|
| 159 | + 'close' => false, |
|
| 160 | + 'param' => array('txt' => $this->_prepareTxt($part[1])), |
|
| 161 | + ); |
|
| 162 | + } else { // else (if we are in a <pre> tag) |
|
| 163 | + // prepare the text |
|
| 164 | + $part[1] = str_replace("\r", '', $part[1]); |
|
| 165 | + $part[1] = explode("\n", $part[1]); |
|
| 166 | + |
|
| 167 | + // foreach line of the text |
|
| 168 | + foreach ($part[1] as $k => $txt) { |
|
| 169 | + // transform the line |
|
| 170 | + $txt = str_replace("\t", self::HTML_TAB, $txt); |
|
| 171 | + $txt = str_replace(' ', ' ', $txt); |
|
| 172 | + |
|
| 173 | + // add a break line |
|
| 174 | + if ($k > 0) $actions[] = $tagPreBr; |
|
| 175 | + |
|
| 176 | + // save the action |
|
| 177 | + $actions[] = array( |
|
| 178 | + 'name' => 'write', |
|
| 179 | + 'close' => false, |
|
| 180 | + 'param' => array('txt' => $this->_prepareTxt($txt, false)), |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // for each indentified action, we have to clean up the begin and the end of the texte |
|
| 188 | + // based on tags that surround it |
|
| 189 | + |
|
| 190 | + // list of the tags to clean |
|
| 191 | + $tagsToClean = array( |
|
| 192 | + 'page', 'page_header', 'page_footer', 'form', |
|
| 193 | + 'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br', |
|
| 194 | + 'div', 'hr', 'p', 'ul', 'ol', 'li', |
|
| 195 | + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
|
| 196 | + 'bookmark', 'fieldset', 'legend', |
|
| 197 | + 'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline', |
|
| 198 | + 'option' |
|
| 199 | + ); |
|
| 200 | + |
|
| 201 | + // foreach action |
|
| 202 | + $nb = count($actions); |
|
| 203 | + for ($k = 0; $k < $nb; $k++) { |
|
| 204 | + // if it is a Text |
|
| 205 | + if ($actions[$k]['name'] == 'write') { |
|
| 206 | + // if the tag before the text is a tag to clean => ltrim on the text |
|
| 207 | + if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) |
|
| 208 | + $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 209 | + |
|
| 210 | + // if the tag after the text is a tag to clean => rtrim on the text |
|
| 211 | + if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) |
|
| 212 | + $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 213 | + |
|
| 214 | + // if the text is empty => remove the action |
|
| 215 | + if ( ! strlen($actions[$k]['param']['txt'])) |
|
| 216 | + unset($actions[$k]); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // if we are not on the level 0 => HTML validator ERROR |
|
| 221 | + if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
| 222 | + |
|
| 223 | + // save the actions to do |
|
| 224 | + $this->code = array_values($actions); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * prepare the text |
|
| 229 | + * |
|
| 230 | + * @param string texte |
|
| 231 | + * @param boolean true => replace multiple space+\t+\r+\n by a single space |
|
| 232 | + * @return string texte |
|
| 233 | + * @access protected |
|
| 234 | + */ |
|
| 235 | + protected function _prepareTxt($txt, $spaces = true) |
|
| 236 | + { |
|
| 237 | + if ($spaces) { |
|
| 238 | + $txt = preg_replace('/\s+/is', ' ', $txt); |
|
| 239 | + } |
|
| 240 | + $txt = str_replace('€', '€', $txt); |
|
| 241 | + $txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding); |
|
| 242 | + return $txt; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * parse the HTML code |
|
| 247 | + * |
|
| 248 | + * @param &array array's result |
|
| 249 | + * @return null |
|
| 250 | + */ |
|
| 251 | + protected function _searchCode(&$tmp) |
|
| 252 | + { |
|
| 253 | + // initialise the array |
|
| 254 | + $tmp = array(); |
|
| 255 | + |
|
| 256 | + // regexp to separate the tags from the texts |
|
| 257 | + $reg = '/(<[^>]+>)|([^<]+)+/isU'; |
|
| 258 | + |
|
| 259 | + // last match found |
|
| 260 | + $str = ''; |
|
| 261 | + $offset = 0; |
|
| 262 | + |
|
| 263 | + // As it finds a match |
|
| 264 | + while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) { |
|
| 265 | + // if it is a tag |
|
| 266 | + if ($parse[1][0]) { |
|
| 267 | + // save the previous text if it exists |
|
| 268 | + if ($str !== '') $tmp[] = array('txt', $str); |
|
| 269 | + |
|
| 270 | + // save the tag, with the offset |
|
| 271 | + $tmp[] = array('code', trim($parse[1][0]), $offset); |
|
| 272 | + |
|
| 273 | + // init the current text |
|
| 274 | + $str = ''; |
|
| 275 | + } else { // else (if it is a text) |
|
| 276 | + // add the new text to the current text |
|
| 277 | + $str .= $parse[2][0]; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + // Update offset to the end of the match |
|
| 281 | + $offset = $parse[0][1] + strlen($parse[0][0]); |
|
| 282 | + unset($parse); |
|
| 283 | + } |
|
| 284 | + // if a text is present in the end, we save it |
|
| 285 | + if ($str != '') $tmp[] = array('txt', $str); |
|
| 286 | + unset($str); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * analise a HTML tag |
|
| 291 | + * |
|
| 292 | + * @param string HTML code to analise |
|
| 293 | + * @return array corresponding action |
|
| 294 | + */ |
|
| 295 | + protected function _analiseCode($code) |
|
| 296 | + { |
|
| 297 | + // name of the tag, opening, closure, autoclosure |
|
| 298 | + $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
|
| 299 | + if ( ! preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
| 300 | + $close = ($match[1] == '/' ? true : false); |
|
| 301 | + $autoclose = preg_match('/\/>$/isU', $code); |
|
| 302 | + $name = strtolower($match[2]); |
|
| 303 | + |
|
| 304 | + // required parameters (depends on the tag name) |
|
| 305 | + $param = array(); |
|
| 306 | + $param['style'] = ''; |
|
| 307 | + if ($name == 'img') { |
|
| 308 | + $param['alt'] = ''; |
|
| 309 | + $param['src'] = ''; |
|
| 310 | + } |
|
| 311 | + if ($name == 'a') { |
|
| 312 | + $param['href'] = ''; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // read the parameters : nom=valeur |
|
| 316 | + $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
|
| 317 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 318 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 319 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 320 | + |
|
| 321 | + // read the parameters : nom="valeur" |
|
| 322 | + $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
|
| 323 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 324 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 325 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 326 | + |
|
| 327 | + // read the parameters : nom='valeur' |
|
| 328 | + $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
|
| 329 | + preg_match_all('/'.$prop.'/is', $code, $match); |
|
| 330 | + for ($k = 0; $k < count($match[0]); $k++) |
|
| 331 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 332 | + |
|
| 333 | + // compliance of each parameter |
|
| 334 | + $color = "#000000"; |
|
| 335 | + $border = null; |
|
| 336 | + foreach ($param as $key => $val) { |
|
| 337 | + $key = strtolower($key); |
|
| 338 | + switch ($key) |
|
| 339 | + { |
|
| 340 | + case 'width': |
|
| 341 | + unset($param[$key]); |
|
| 342 | + $param['style'] .= 'width: '.$val.'px; '; |
|
| 343 | + break; |
|
| 344 | + |
|
| 345 | + case 'align': |
|
| 346 | + if ($name === 'img') { |
|
| 347 | + unset($param[$key]); |
|
| 348 | + $param['style'] .= 'float: '.$val.'; '; |
|
| 349 | + } elseif ($name !== 'table') { |
|
| 350 | + unset($param[$key]); |
|
| 351 | + $param['style'] .= 'text-align: '.$val.'; '; |
|
| 352 | + } |
|
| 353 | + break; |
|
| 354 | + |
|
| 355 | + case 'valign': |
|
| 356 | + unset($param[$key]); |
|
| 357 | + $param['style'] .= 'vertical-align: '.$val.'; '; |
|
| 358 | + break; |
|
| 359 | + |
|
| 360 | + case 'height': |
|
| 361 | + unset($param[$key]); |
|
| 362 | + $param['style'] .= 'height: '.$val.'px; '; |
|
| 363 | + break; |
|
| 364 | + |
|
| 365 | + case 'bgcolor': |
|
| 366 | + unset($param[$key]); |
|
| 367 | + $param['style'] .= 'background: '.$val.'; '; |
|
| 368 | + break; |
|
| 369 | + |
|
| 370 | + case 'bordercolor': |
|
| 371 | + unset($param[$key]); |
|
| 372 | + $color = $val; |
|
| 373 | + break; |
|
| 374 | + |
|
| 375 | + case 'border': |
|
| 376 | + unset($param[$key]); |
|
| 377 | + if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
| 378 | + $border = $val; |
|
| 379 | + break; |
|
| 380 | + |
|
| 381 | + case 'cellpadding': |
|
| 382 | + case 'cellspacing': |
|
| 383 | + if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
| 384 | + break; |
|
| 385 | + |
|
| 386 | + case 'colspan': |
|
| 387 | + case 'rowspan': |
|
| 388 | + $val = preg_replace('/[^0-9]/isU', '', $val); |
|
| 389 | + if ( ! $val) $val = 1; |
|
| 390 | + $param[$key] = $val; |
|
| 391 | + break; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + // compliance of the border |
|
| 396 | + if ($border !== null) { |
|
| 397 | + if ($border) $border = 'border: solid '.$border.' '.$color; |
|
| 398 | + else $border = 'border: none'; |
|
| 399 | + |
|
| 400 | + $param['style'] .= $border.'; '; |
|
| 401 | + $param['border'] = $border; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // reading styles: decomposition and standardization |
|
| 405 | + $styles = explode(';', $param['style']); |
|
| 406 | + $param['style'] = array(); |
|
| 407 | + foreach ($styles as $style) { |
|
| 408 | + $tmp = explode(':', $style); |
|
| 409 | + if (count($tmp) > 1) { |
|
| 410 | + $cod = $tmp[0]; |
|
| 411 | + unset($tmp[0]); |
|
| 412 | + $tmp = implode(':', $tmp); |
|
| 413 | + $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // determining the level of table opening, with an added level |
|
| 418 | + if (in_array($name, array('ul', 'ol', 'table')) && ! $close) { |
|
| 419 | + $this->_num++; |
|
| 420 | + $this->_level[count($this->_level)] = $this->_num; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + // get the level of the table containing the element |
|
| 424 | + if ( ! isset($param['num'])) { |
|
| 425 | + $param['num'] = $this->_level[count($this->_level) - 1]; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // for closures table: remove a level |
|
| 429 | + if (in_array($name, array('ul', 'ol', 'table')) && $close) { |
|
| 430 | + unset($this->_level[count($this->_level) - 1]); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // prepare the parameters |
|
| 434 | + if (isset($param['value'])) { |
|
| 435 | + $param['value'] = $this->_prepareTxt($param['value']); |
|
| 436 | + } |
|
| 437 | + if (isset($param['alt'])) { |
|
| 438 | + $param['alt'] = $this->_prepareTxt($param['alt']); |
|
| 439 | + } |
|
| 440 | + if (isset($param['title'])) { |
|
| 441 | + $param['title'] = $this->_prepareTxt($param['title']); |
|
| 442 | + } |
|
| 443 | + if (isset($param['class'])) { |
|
| 444 | + $param['class'] = $this->_prepareTxt($param['class']); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // return the new action to do |
|
| 448 | + return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * get a full level of HTML, between an opening and closing corresponding |
|
| 453 | + * |
|
| 454 | + * @param integer key |
|
| 455 | + * @param integer $k |
|
| 456 | + * @return array actions |
|
| 457 | + */ |
|
| 458 | + public function getLevel($k) |
|
| 459 | + { |
|
| 460 | + // if the code does not exist => return empty |
|
| 461 | + if ( ! isset($this->code[$k])) return array(); |
|
| 462 | + |
|
| 463 | + // the tag to detect |
|
| 464 | + $detect = $this->code[$k]['name']; |
|
| 465 | + |
|
| 466 | + // if it is a text => return |
|
| 467 | + if ($detect == 'write') { |
|
| 468 | + return array($this->code[$k]); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + // |
|
| 472 | + $level = 0; // depth level |
|
| 473 | + $end = false; // end of the search |
|
| 474 | + $code = array(); // extract code |
|
| 475 | + |
|
| 476 | + // while it's not ended |
|
| 477 | + while ( ! $end) { |
|
| 478 | + // current action |
|
| 479 | + $row = $this->code[$k]; |
|
| 480 | + |
|
| 481 | + // if 'write' => we add the text |
|
| 482 | + if ($row['name'] == 'write') { |
|
| 483 | + $code[] = $row; |
|
| 484 | + } else { // else, it is a html tag |
|
| 485 | + $not = false; // flag for not taking into account the current tag |
|
| 486 | + |
|
| 487 | + // if it is the searched tag |
|
| 488 | + if ($row['name'] == $detect) { |
|
| 489 | + // if we are just at the root level => dont take it |
|
| 490 | + if ($level == 0) { |
|
| 491 | + $not = true; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // update the level |
|
| 495 | + $level += ($row['close'] ? -1 : 1); |
|
| 496 | + |
|
| 497 | + // if we are now at the root level => it is the end, and dont take it |
|
| 498 | + if ($level == 0) { |
|
| 499 | + $not = true; |
|
| 500 | + $end = true; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + // if we can takin into account the current tag => save it |
|
| 505 | + if ( ! $not) { |
|
| 506 | + if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
| 507 | + $code[] = $row; |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + // it continues as long as there has code to analise |
|
| 512 | + if (isset($this->code[$k + 1])) |
|
| 513 | + $k++; |
|
| 514 | + else |
|
| 515 | + $end = true; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + // return the extract |
|
| 519 | + return $code; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * return a part of the HTML code, for error message |
|
| 524 | + * |
|
| 525 | + * @param integer position |
|
| 526 | + * @param integer take before |
|
| 527 | + * @param integer take after |
|
| 528 | + * @return string part of the html code |
|
| 529 | + */ |
|
| 530 | + public function getHtmlErrorCode($pos, $before = 30, $after = 40) |
|
| 531 | + { |
|
| 532 | + return substr($this->_html, $pos - $before, $before + $after); |
|
| 533 | + } |
|
| 534 | 534 | } |
@@ -115,12 +115,13 @@ discard block |
||
| 115 | 115 | // if it is a closure tag |
| 116 | 116 | if ($res['close']) { |
| 117 | 117 | // HTML validation |
| 118 | - if (count($parents) < 1) |
|
| 119 | - throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | - else if ($parents[count($parents) - 1] != $res['name']) |
|
| 121 | - throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | - else |
|
| 123 | - unset($parents[count($parents) - 1]); |
|
| 118 | + if (count($parents) < 1) { |
|
| 119 | + throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos'])); |
|
| 120 | + } else if ($parents[count($parents) - 1] != $res['name']) { |
|
| 121 | + throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos'])); |
|
| 122 | + } else { |
|
| 123 | + unset($parents[count($parents) - 1]); |
|
| 124 | + } |
|
| 124 | 125 | } else { |
| 125 | 126 | // if it is a autoclosed tag |
| 126 | 127 | if ($res['autoclose']) { |
@@ -171,7 +172,9 @@ discard block |
||
| 171 | 172 | $txt = str_replace(' ', ' ', $txt); |
| 172 | 173 | |
| 173 | 174 | // add a break line |
| 174 | - if ($k > 0) $actions[] = $tagPreBr; |
|
| 175 | + if ($k > 0) { |
|
| 176 | + $actions[] = $tagPreBr; |
|
| 177 | + } |
|
| 175 | 178 | |
| 176 | 179 | // save the action |
| 177 | 180 | $actions[] = array( |
@@ -204,21 +207,26 @@ discard block |
||
| 204 | 207 | // if it is a Text |
| 205 | 208 | if ($actions[$k]['name'] == 'write') { |
| 206 | 209 | // if the tag before the text is a tag to clean => ltrim on the text |
| 207 | - if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) |
|
| 208 | - $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 210 | + if ($k > 0 && in_array($actions[$k - 1]['name'], $tagsToClean)) { |
|
| 211 | + $actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']); |
|
| 212 | + } |
|
| 209 | 213 | |
| 210 | 214 | // if the tag after the text is a tag to clean => rtrim on the text |
| 211 | - if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) |
|
| 212 | - $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 215 | + if ($k < $nb - 1 && in_array($actions[$k + 1]['name'], $tagsToClean)) { |
|
| 216 | + $actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']); |
|
| 217 | + } |
|
| 213 | 218 | |
| 214 | 219 | // if the text is empty => remove the action |
| 215 | - if ( ! strlen($actions[$k]['param']['txt'])) |
|
| 216 | - unset($actions[$k]); |
|
| 220 | + if ( ! strlen($actions[$k]['param']['txt'])) { |
|
| 221 | + unset($actions[$k]); |
|
| 222 | + } |
|
| 217 | 223 | } |
| 218 | 224 | } |
| 219 | 225 | |
| 220 | 226 | // if we are not on the level 0 => HTML validator ERROR |
| 221 | - if (count($parents)) throw new HTML2PDF_exception(5, $parents); |
|
| 227 | + if (count($parents)) { |
|
| 228 | + throw new HTML2PDF_exception(5, $parents); |
|
| 229 | + } |
|
| 222 | 230 | |
| 223 | 231 | // save the actions to do |
| 224 | 232 | $this->code = array_values($actions); |
@@ -265,7 +273,9 @@ discard block |
||
| 265 | 273 | // if it is a tag |
| 266 | 274 | if ($parse[1][0]) { |
| 267 | 275 | // save the previous text if it exists |
| 268 | - if ($str !== '') $tmp[] = array('txt', $str); |
|
| 276 | + if ($str !== '') { |
|
| 277 | + $tmp[] = array('txt', $str); |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | 280 | // save the tag, with the offset |
| 271 | 281 | $tmp[] = array('code', trim($parse[1][0]), $offset); |
@@ -282,7 +292,9 @@ discard block |
||
| 282 | 292 | unset($parse); |
| 283 | 293 | } |
| 284 | 294 | // if a text is present in the end, we save it |
| 285 | - if ($str != '') $tmp[] = array('txt', $str); |
|
| 295 | + if ($str != '') { |
|
| 296 | + $tmp[] = array('txt', $str); |
|
| 297 | + } |
|
| 286 | 298 | unset($str); |
| 287 | 299 | } |
| 288 | 300 | |
@@ -296,7 +308,9 @@ discard block |
||
| 296 | 308 | { |
| 297 | 309 | // name of the tag, opening, closure, autoclosure |
| 298 | 310 | $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
| 299 | - if ( ! preg_match('/'.$tag.'/isU', $code, $match)) return null; |
|
| 311 | + if ( ! preg_match('/'.$tag.'/isU', $code, $match)) { |
|
| 312 | + return null; |
|
| 313 | + } |
|
| 300 | 314 | $close = ($match[1] == '/' ? true : false); |
| 301 | 315 | $autoclose = preg_match('/\/>$/isU', $code); |
| 302 | 316 | $name = strtolower($match[2]); |
@@ -315,20 +329,23 @@ discard block |
||
| 315 | 329 | // read the parameters : nom=valeur |
| 316 | 330 | $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
| 317 | 331 | preg_match_all('/'.$prop.'/is', $code, $match); |
| 318 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 319 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 332 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 333 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 334 | + } |
|
| 320 | 335 | |
| 321 | 336 | // read the parameters : nom="valeur" |
| 322 | 337 | $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
| 323 | 338 | preg_match_all('/'.$prop.'/is', $code, $match); |
| 324 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 325 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 339 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 340 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 341 | + } |
|
| 326 | 342 | |
| 327 | 343 | // read the parameters : nom='valeur' |
| 328 | 344 | $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
| 329 | 345 | preg_match_all('/'.$prop.'/is', $code, $match); |
| 330 | - for ($k = 0; $k < count($match[0]); $k++) |
|
| 331 | - $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 346 | + for ($k = 0; $k < count($match[0]); $k++) { |
|
| 347 | + $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
|
| 348 | + } |
|
| 332 | 349 | |
| 333 | 350 | // compliance of each parameter |
| 334 | 351 | $color = "#000000"; |
@@ -374,19 +391,25 @@ discard block |
||
| 374 | 391 | |
| 375 | 392 | case 'border': |
| 376 | 393 | unset($param[$key]); |
| 377 | - if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px'; |
|
| 394 | + if (preg_match('/^[0-9]+$/isU', $val)) { |
|
| 395 | + $val = $val.'px'; |
|
| 396 | + } |
|
| 378 | 397 | $border = $val; |
| 379 | 398 | break; |
| 380 | 399 | |
| 381 | 400 | case 'cellpadding': |
| 382 | 401 | case 'cellspacing': |
| 383 | - if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
|
| 402 | + if (preg_match('/^([0-9]+)$/isU', $val)) { |
|
| 403 | + $param[$key] = $val.'px'; |
|
| 404 | + } |
|
| 384 | 405 | break; |
| 385 | 406 | |
| 386 | 407 | case 'colspan': |
| 387 | 408 | case 'rowspan': |
| 388 | 409 | $val = preg_replace('/[^0-9]/isU', '', $val); |
| 389 | - if ( ! $val) $val = 1; |
|
| 410 | + if ( ! $val) { |
|
| 411 | + $val = 1; |
|
| 412 | + } |
|
| 390 | 413 | $param[$key] = $val; |
| 391 | 414 | break; |
| 392 | 415 | } |
@@ -394,8 +417,11 @@ discard block |
||
| 394 | 417 | |
| 395 | 418 | // compliance of the border |
| 396 | 419 | if ($border !== null) { |
| 397 | - if ($border) $border = 'border: solid '.$border.' '.$color; |
|
| 398 | - else $border = 'border: none'; |
|
| 420 | + if ($border) { |
|
| 421 | + $border = 'border: solid '.$border.' '.$color; |
|
| 422 | + } else { |
|
| 423 | + $border = 'border: none'; |
|
| 424 | + } |
|
| 399 | 425 | |
| 400 | 426 | $param['style'] .= $border.'; '; |
| 401 | 427 | $param['border'] = $border; |
@@ -458,7 +484,9 @@ discard block |
||
| 458 | 484 | public function getLevel($k) |
| 459 | 485 | { |
| 460 | 486 | // if the code does not exist => return empty |
| 461 | - if ( ! isset($this->code[$k])) return array(); |
|
| 487 | + if ( ! isset($this->code[$k])) { |
|
| 488 | + return array(); |
|
| 489 | + } |
|
| 462 | 490 | |
| 463 | 491 | // the tag to detect |
| 464 | 492 | $detect = $this->code[$k]['name']; |
@@ -503,16 +531,19 @@ discard block |
||
| 503 | 531 | |
| 504 | 532 | // if we can takin into account the current tag => save it |
| 505 | 533 | if ( ! $not) { |
| 506 | - if (isset($row['style']['text-align'])) unset($row['style']['text-align']); |
|
| 534 | + if (isset($row['style']['text-align'])) { |
|
| 535 | + unset($row['style']['text-align']); |
|
| 536 | + } |
|
| 507 | 537 | $code[] = $row; |
| 508 | 538 | } |
| 509 | 539 | } |
| 510 | 540 | |
| 511 | 541 | // it continues as long as there has code to analise |
| 512 | - if (isset($this->code[$k + 1])) |
|
| 513 | - $k++; |
|
| 514 | - else |
|
| 515 | - $end = true; |
|
| 542 | + if (isset($this->code[$k + 1])) { |
|
| 543 | + $k++; |
|
| 544 | + } else { |
|
| 545 | + $end = true; |
|
| 546 | + } |
|
| 516 | 547 | } |
| 517 | 548 | |
| 518 | 549 | // return the extract |
@@ -1123,7 +1123,7 @@ discard block |
||
| 1123 | 1123 | * @param array $frame |
| 1124 | 1124 | * @param int $maskNo |
| 1125 | 1125 | * @param int $level |
| 1126 | - * @return array mask |
|
| 1126 | + * @return integer mask |
|
| 1127 | 1127 | */ |
| 1128 | 1128 | protected function makeMask($width, $frame, $maskNo, $level) { |
| 1129 | 1129 | $masked = array_fill(0, $width, str_repeat("\0", $width)); |
@@ -1165,7 +1165,7 @@ discard block |
||
| 1165 | 1165 | /** |
| 1166 | 1166 | * evaluateSymbol |
| 1167 | 1167 | * @param int $width |
| 1168 | - * @param array $frame |
|
| 1168 | + * @param integer $frame |
|
| 1169 | 1169 | * @return int demerit |
| 1170 | 1170 | */ |
| 1171 | 1171 | protected function evaluateSymbol($width, $frame) { |
@@ -2035,7 +2035,7 @@ discard block |
||
| 2035 | 2035 | |
| 2036 | 2036 | /** |
| 2037 | 2037 | * convertData |
| 2038 | - * @param array $items |
|
| 2038 | + * @param integer $items |
|
| 2039 | 2039 | * @return array items |
| 2040 | 2040 | */ |
| 2041 | 2041 | protected function convertData($items) { |
@@ -2490,7 +2490,7 @@ discard block |
||
| 2490 | 2490 | |
| 2491 | 2491 | /** |
| 2492 | 2492 | * Return BCH encoded format information pattern. |
| 2493 | - * @param array $mask |
|
| 2493 | + * @param integer $mask |
|
| 2494 | 2494 | * @param int $level error correction level |
| 2495 | 2495 | * @return BCH encoded format information pattern |
| 2496 | 2496 | */ |
@@ -264,12 +264,12 @@ |
||
| 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 string[] 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 string[] 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 { |
@@ -180,12 +180,12 @@ discard block |
||
| 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. |
@@ -195,7 +195,7 @@ discard block |
||
| 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,7 +204,7 @@ 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 |
@@ -218,12 +218,12 @@ discard block |
||
| 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 | - define('N2', 3); |
|
| 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) |
@@ -260,18 +260,18 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | // #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*# |
| 262 | 262 | |
| 263 | -if (!class_exists('QRcode', false)) { |
|
| 263 | +if ( ! class_exists('QRcode', false)) { |
|
| 264 | 264 | |
| 265 | 265 | // for compaibility with PHP4 |
| 266 | - if (!function_exists('str_split')) { |
|
| 266 | + if ( ! function_exists('str_split')) { |
|
| 267 | 267 | /** |
| 268 | 268 | * Convert a string to an array (needed for PHP4 compatibility) |
| 269 | 269 | * @param string $string The input string. |
| 270 | 270 | * @param int $split_length Maximum length of the chunk. |
| 271 | 271 | * @return string[] 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 | 272 | */ |
| 273 | - function str_split($string, $split_length=1) { |
|
| 274 | - if ((strlen($string) > $split_length) OR (!$split_length)) { |
|
| 273 | + function str_split($string, $split_length = 1) { |
|
| 274 | + if ((strlen($string) > $split_length) OR ( ! $split_length)) { |
|
| 275 | 275 | do { |
| 276 | 276 | $c = strlen($string); |
| 277 | 277 | $parts[] = substr($string, 0, $split_length); |
@@ -64,6 +64,7 @@ |
||
| 64 | 64 | * Custom query result. |
| 65 | 65 | * |
| 66 | 66 | * @param class_name A string that represents the type of object you want back |
| 67 | + * @param string $class_name |
|
| 67 | 68 | * @return array of objects |
| 68 | 69 | */ |
| 69 | 70 | public function custom_result_object($class_name) |
@@ -164,6 +164,7 @@ |
||
| 164 | 164 | * |
| 165 | 165 | * @access private called by execute() |
| 166 | 166 | * @param string an SQL query |
| 167 | + * @param string $sql |
|
| 167 | 168 | * @return string |
| 168 | 169 | */ |
| 169 | 170 | function _prep_query($sql) |
@@ -338,13 +338,15 @@ |
||
| 338 | 338 | */ |
| 339 | 339 | function count_all($table = '') |
| 340 | 340 | { |
| 341 | - if ($table == '') |
|
| 342 | - return '0'; |
|
| 341 | + if ($table == '') { |
|
| 342 | + return '0'; |
|
| 343 | + } |
|
| 343 | 344 | |
| 344 | 345 | $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); |
| 345 | 346 | |
| 346 | - if ($query->num_rows() == 0) |
|
| 347 | - return '0'; |
|
| 347 | + if ($query->num_rows() == 0) { |
|
| 348 | + return '0'; |
|
| 349 | + } |
|
| 348 | 350 | |
| 349 | 351 | $row = $query->row(); |
| 350 | 352 | $this->_reset_select(); |
@@ -314,15 +314,15 @@ |
||
| 314 | 314 | // -------------------------------------------------------------------- |
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | - * Parse major version |
|
| 318 | - * |
|
| 319 | - * Grabs the major version number from the |
|
| 320 | - * database server version string passed in. |
|
| 321 | - * |
|
| 322 | - * @access private |
|
| 323 | - * @param string $version |
|
| 324 | - * @return string major version number |
|
| 325 | - */ |
|
| 317 | + * Parse major version |
|
| 318 | + * |
|
| 319 | + * Grabs the major version number from the |
|
| 320 | + * database server version string passed in. |
|
| 321 | + * |
|
| 322 | + * @access private |
|
| 323 | + * @param string $version |
|
| 324 | + * @return string major version number |
|
| 325 | + */ |
|
| 326 | 326 | function _parse_major_version($version) |
| 327 | 327 | { |
| 328 | 328 | preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); |