Revize 427
Přidáno uživatelem Tomáš Dulík před asi 15 roky(ů)
freenetis/trunk/kohana/application/models/account_attribute.php | ||
---|---|---|
public static $bank_fees = '549001'; // created in installation
|
||
public static $bank_interests = '644000'; // created in installation
|
||
public static $member_fees = '684000'; // created in installation
|
||
public static $time_deposits_interests = '655000';
|
||
public static $time_deposits = '259000';
|
||
|
||
/**
|
||
* The constructor is used for filling the double accounts numbers from the database.
|
freenetis/trunk/kohana/application/models/bank_transfer.php | ||
---|---|---|
|
||
/**
|
||
* @author Tomas Dulik
|
||
* @return true if the bank transfer was already imported
|
||
* @return object containing possible duplicities
|
||
* @param $data - object containing info about a bank transfer (from the bank account listing)
|
||
* parsed_acc_nr => 184932848 //cislo parsovaneho uctu
|
||
* parsed_acc_bank_nr=> 2400 //cislo banky parsovaneho uctu
|
||
... | ... | |
* specific_symbol => 9876543210
|
||
* amount => 720.00
|
||
* fee => -6.90
|
||
*
|
||
* The cardinalities of a real-life bank_transfers JOIN transfers table with 10453 rows:
|
||
* datetime:4165, text:3063, variable_symbol:2173 bt.origin_id:1912
|
||
*/
|
||
public static function exists($data) {
|
||
return false;
|
||
$q="SELECT * FROM bank_transfers
|
||
JOIN transfers ON bank_transfers.transfer_id=transfers.id
|
||
AND bank_transfers.datetime=$data->date_time";
|
||
return self::$db->query($q)->count();
|
||
public static function get_duplicities($data) {
|
||
if (empty($data->variable_symbol)) $cond_vs="IS NULL";
|
||
else $cond_vs="=$data->variable_symbol";
|
||
$q="SELECT t.datetime, t.creation_datetime, t.text, bt.*
|
||
FROM bank_transfers AS bt JOIN transfers AS t
|
||
ON bt.transfer_id=t.id
|
||
AND t.datetime='$data->date_time'
|
||
AND t.text='$data->comment'
|
||
AND bt.variable_symbol $cond_vs";
|
||
return self::$db->query($q);
|
||
}
|
||
|
||
}
|
freenetis/trunk/kohana/application/controllers/accounts.php | ||
---|---|---|
<?php
|
||
class Duplicity_Exception extends Exception {}
|
||
class Duplicity_Exception extends Exception {
|
||
public $duplicity;
|
||
public function __construct($duplicity=NULL) {$this->duplicity=$duplicity;}
|
||
}
|
||
|
||
class Accounts_Controller extends Controller
|
||
{
|
||
... | ... | |
/** zde jsou statické objekty, jejichž instance tvořím jen jednou u importu prvního řádku
|
||
* výpisu (šetříme paměť...)
|
||
* */
|
||
static $acc_model;
|
||
static $bank_acc_model;
|
||
static $member_model;
|
||
static $fee_model;
|
||
static $parsed_acc;
|
||
static $bank_interests;
|
||
static $bank_fees;
|
||
static $suppliers;
|
||
static $operating;
|
||
static $member_fees;
|
||
static $acc_model, $bank_acc_model, $member_model, $fee_model, $parsed_acc;
|
||
static $bank_interests, $bank_fees, $time_deposits_interests, $time_deposits;
|
||
static $suppliers, $operating, $member_fees, $cash;
|
||
static $first_pass=true;
|
||
|
||
$this->stats->linenr++;
|
||
... | ... | |
// s podvojným účtem přes tabulku accounts_bank_accounts
|
||
throw new Kohana_User_Exception('Kritická chyba', 'V tabulce accounts_bank_accounts chybí vazba bankovního a podvojného účtu sdružení');
|
||
}
|
||
|
||
$bank_interests = $this->parsed_bank_acc->get_related_account_by_attribute_id(
|
||
Account_attribute_Model::$bank_interests);
|
||
if ($bank_interests===FALSE) { // pokud ucet uroku neexistuje, pak si jej vytvorime
|
||
$bank_interests=Account_Model::create(Account_attribute_Model::$bank_interests,
|
||
"Úroky z $parsed_acc->name", 1);
|
||
$bank_interests->add_bank_account($this->parsed_bank_acc);
|
||
}
|
||
$bank_fees = $this->parsed_bank_acc->get_related_account_by_attribute_id(
|
||
Account_attribute_Model::$bank_fees);
|
||
if ($bank_fees===FALSE) { // pokud ucet poplatku neexistuje, pak jej vytvorime
|
||
$bank_fees=Account_Model::create(Account_attribute_Model::$bank_fees,
|
||
"Poplatky z $parsed_acc->name", 1);
|
||
$bank_fees->add_bank_account($this->parsed_bank_acc);
|
||
}
|
||
// Teď potřebujeme najít nebo vytvořit speciální podvojné účty k parsovanému bank. učtu:
|
||
$spec_accounts=array(
|
||
"bank_interests" => "Úroky z $parsed_acc->name",
|
||
"time_deposits_interests" => "Úroky z termín. vkladů $parsed_acc->name",
|
||
"time_deposits" => "Termínované vklady $parsed_acc->name",
|
||
"bank_fees" => "Poplatky z $parsed_acc->name"
|
||
);
|
||
foreach ($spec_accounts as $accnt=>$name) {
|
||
$spec_acc=$this->parsed_bank_acc->get_related_account_by_attribute_id(
|
||
Account_attribute_Model::$$accnt);
|
||
if ($spec_acc===FALSE) { // pokud spec. ucet neexistuje, pak si jej vytvorime
|
||
$spec_acc=Account_Model::create(Account_attribute_Model::$$accnt, $name, 1);
|
||
$spec_acc->add_bank_account($this->parsed_bank_acc);
|
||
}
|
||
$$accnt=$spec_acc;
|
||
}
|
||
|
||
$suppliers=ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$suppliers);
|
||
$member_fees=ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$member_fees);
|
||
$operating=ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$operating);
|
||
$cash=ORM::factory('account')->find_by_account_attribute_id(Account_attribute_Model::$cash);
|
||
|
||
if (!$suppliers->id || !$member_fees->id || !$operating->id)
|
||
throw new Kohana_User_Exception('Kritická chyba', 'V DB chybí účet member_fees, suppliers nebo operating');
|
||
$first_pass=FALSE;
|
||
}
|
||
|
||
if (!empty($data->fee)) {
|
||
$fee=abs($data->fee);
|
||
$this->stats->bank_fees+=$fee;
|
||
$this->stats->bank_fees_nr++;
|
||
}
|
||
|
||
// ********************** Tak a jdeme tvořit transakce *********************
|
||
$vs=trim($data->variable_symbol);
|
||
if (empty($data->amount)) {
|
||
// ****** Bankovní poplatky: ebanka má v řádku výpisu pouze poplatek, ale castka==0
|
||
// vytvoříme transakci "bankovní poplatek z 221000 (bank. účty) na 549001 (bank. poplatky)
|
||
//a bankovní transakci z parsovaného účtu na null. Přiřadíme ji sdružení (member_id=1).
|
||
if (empty($data->comment)) $data->comment=$data->type;
|
||
$fee=abs($data->fee);
|
||
$this->create_transfers($parsed_acc, $bank_fees, $fee,
|
||
$this->parsed_bank_acc, null, $data, 1);
|
||
$this->stats->bank_fees+=$fee;
|
||
$this->stats->bank_fees_nr++;
|
||
}
|
||
else // amount je nenulovy
|
||
if (!empty($data->amount) && empty($data->fee)) {
|
||
// ***** úroky u ebanky: částka!=0 a poplatek==0
|
||
// Vytvoříme transakci z 644000 (uroky) na 221000
|
||
} else // castka je nenulova:
|
||
if (empty($data->fee) && stripos($data->type, "rok") !== FALSE) {
|
||
// ***** úroky u ebanky: amount!=0, fee==0, type je "Úrok", "Kladný úrok", "Převedení úroku po kapitalizaci TV"
|
||
// Vytvoříme transakci z 644000 nebo 655000 (uroky) na 221000
|
||
// a bankovní transakci z null na parsovaný účet. Přiřadíme ji sdružení (member_id=1)
|
||
$this->create_transfers($bank_interests, $parsed_acc, $data->amount,
|
||
null, $this->parsed_bank_acc, $data, 1);
|
||
if (empty($vs)) // běžný úrok? (644000)
|
||
$this->create_transfers($interests, $parsed_acc, $data->amount,
|
||
null, $this->parsed_bank_acc, $data, 1);
|
||
else // úrok z termínovaného vkladu (655000)
|
||
$this->create_transfers($time_deposit_interests, $parsed_acc, $data->amount,
|
||
null, $this->parsed_bank_acc, $data, 1);
|
||
$this->stats->interests += $data->amount;
|
||
$this->stats->interests_nr++;
|
||
} else {
|
||
// ****** castka!=0 && poplatek !=0 - u ebanky nejběžnější případ: ******
|
||
// ****** členský příspěvek nebo platba faktury dodavatelum. ******
|
||
// ****** nejběžnější případ:
|
||
// - členský příspěvek, platba faktury dodavatelum, termín. vklad, výběr hotovosti ******
|
||
// Nejdriv zkusím najít majitele bankovního protiúčtu
|
||
$ks=trim($data->constant_symbol);
|
||
$term_vklad = ($ks == "968");
|
||
$member_model->clear();
|
||
$member=$member_model;
|
||
$vs=trim($data->variable_symbol);
|
||
if ($data->amount>0 && !empty($vs)) {
|
||
// členský příspěvek: uvedl člen u teto platby jako variabilni symbol (VS) svůj telefon ?
|
||
$member=$member_model->find_member_by_phone($vs);
|
||
|
||
if ($member===FALSE ) { // find_member_by_phone vrací false, pokud nic nenajde
|
||
|
||
if ($term_vklad) $member->id=1; // term. vklad vždy způsobuje samo sdružení
|
||
//u ostatních typů transakcí zkusíme najít původce:
|
||
else if ($data->amount>0 && !empty($vs)) {
|
||
// členský příspěvek nebo příjem z faktury odběrateli
|
||
// @todo zpracování jiných typů VS u člen. příspěvků (např. ID+CRC16)
|
||
// uvedl člen u teto platby jako variabilni symbol (VS) svůj telefon ?
|
||
$member=$member_model->find_member_by_phone($vs);
|
||
if ($member===FALSE ) { // find_member_by_phone vrací false, pokud nic nenajde
|
||
// ne? zkusime, zda jako VS nezadal svoje member_id + crc16(member_id)
|
||
// $member=$member_model->get_member_by_crc_id($vs); // this function has bugs!!! needs rewrite!!!
|
||
$member=$member_model;
|
||
$this->stats->unasigned++;
|
||
}
|
||
// pokud se to nepovedlo, pak $member->id nastavíme na null
|
||
} // else { // platba přijaté faktury - majitele účtu najdeme dle VS na faktuře, až budeme mít modul přijatých faktur}
|
||
}
|
||
// else { // platba přijaté faktury - majitele účtu najdeme dle VS na faktuře, až budeme mít modul přijatých faktur}
|
||
|
||
// ***Tady si vytvorime instanci účtu clena (nebo dodavatele) z prave nacteneho vypisu:
|
||
$bank_acc=$bank_acc_model->find_by_account_nr_and_bank_nr($data->account_nr, $data->account_bank_nr);
|
||
|
||
$bank_acc=$bank_acc_model->find_by_account_nr_and_bank_nr($data->account_nr, $data->account_bank_nr);
|
||
if (!$bank_acc->id) { // bank. ucet clena neexistuje, tak si ho vytvorime
|
||
$bank_acc->clear();
|
||
$bank_acc->member_id = $member->id;
|
||
... | ... | |
// $bank_acc->add_account($member_fees); //tuto vazbu bych tvořil jen pokud bych chtěl evidovat pohyby na bank. účtech členů
|
||
}
|
||
if ($data->amount<0) {
|
||
if (!$member->id && $bank_acc->member_id) // pokud se předtím nepodařilo najít majitele dle VS
|
||
$member = $member_model->find($bank_acc->member_id); // zkusím ho vzít odsud
|
||
// úhrada faktury - z 221000 (bank. účet) na 321000 (dodavatelé)
|
||
$amount=abs($data->amount);
|
||
$id=$this->create_transfers($parsed_acc, $suppliers, $amount,
|
||
$this->parsed_bank_acc, $bank_acc, $data, $member->id);
|
||
// a ještě vytvoříme transakce (podvojné+bankovní) bank. poplatku
|
||
// vytvoříme transakci "bankovní poplatek z 221000 (bank. účty) na 549001 (bank. poplatky)
|
||
//a bankovní transakci z parsovaného účtu na null
|
||
$data->comment = "Bank. poplatek". (!empty($data->comment) ? " ($data->comment)":"");
|
||
$fee=abs($data->fee);
|
||
$this->create_transfers($parsed_acc, $bank_fees, $fee,
|
||
$this->parsed_bank_acc, null, $data, $member->id, $id);
|
||
$this->stats->invoices+=$amount;
|
||
$this->stats->invoices_nr++;
|
||
$this->stats->bank_fees+=$fee;
|
||
$this->stats->bank_fees_nr++;
|
||
$amount=abs($data->amount);
|
||
if ($term_vklad) { // převod peněz na účet term. vkladu
|
||
$id=$this->create_transfers($parsed_acc, $time_deposits, $amount,
|
||
$this->parsed_bank_acc, $bank_acc, $data, $member->id, null);
|
||
$this->stats->time_deposits_drawn+=$amount;
|
||
$this->stats->time_deposits_drawn_nr++;
|
||
} else {
|
||
if (stripos($data->type, "hotovost") !== FALSE) { // výběr do pokladny ?
|
||
$id=$this->create_transfers($parsed_acc, $cash, $amount,
|
||
$this->parsed_bank_acc, null, $data, $member->id, null);
|
||
$this->stats->cash_drawn+=$amount;
|
||
$this->stats->cash_drawn_nr++;
|
||
} else {
|
||
// úhrada faktury - z 221000 (bank. účet) na 321000 (dodavatelé)
|
||
if (!$member->id && $bank_acc->member_id) // pokud se předtím nepodařilo najít majitele dle VS
|
||
$member = $member_model->find($bank_acc->member_id); // zkusím ho vzít odsud
|
||
$id=$this->create_transfers($parsed_acc, $suppliers, $amount,
|
||
$this->parsed_bank_acc, $bank_acc, $data, $member->id);
|
||
$this->stats->invoices+=$amount;
|
||
$this->stats->invoices_nr++;
|
||
}
|
||
} // if ($term_vklad) ... else
|
||
if (!empty($fee)) {
|
||
// je tam bankovní poplatek - vytvoříme:
|
||
// - podvojnou transakci z 221000 (bank. účty) na 549001 (bank. poplatky)
|
||
// - bankovní transakci z parsovaného účtu na null
|
||
$data->comment = "Bank. poplatek". (!empty($data->comment) ? " ($data->comment)":"");
|
||
$this->create_transfers($parsed_acc, $bank_fees, $fee,
|
||
$this->parsed_bank_acc, null, $data, $member->id, $id);
|
||
}
|
||
} else { // $data->amount > 0
|
||
// členský příspěvek - vytvoříme:
|
||
// - podvojnou transakci z 684000 na 221000
|
||
// - bankovní transakci z bank. účtu člena na bank. účet sdružení
|
||
$id=$this->create_transfers($member_fees, $parsed_acc, $data->amount,
|
||
$bank_acc, $this->parsed_bank_acc, $data, $member->id);
|
||
// bankovní poplatek - vytvoříme:
|
||
// - podvojnou transakci z 221000 (bank. účty) na 549001 (bank. poplatky)
|
||
// - bankovní transakci z parsovaného účtu na null
|
||
$data->comment = "Bank. poplatek". (!empty($data->comment) ? " ($data->comment)":"");
|
||
$fee=abs($data->fee);
|
||
$this->stats->bank_fees+=$fee;
|
||
$this->stats->bank_fees_nr++;
|
||
$this->create_transfers($parsed_acc, $bank_fees, $fee,
|
||
$this->parsed_bank_acc, null, $data, $member->id, $id);
|
||
// naše správní rada si vymyslela, že poplatek budeme dotovat z operačního účtu
|
||
// (pokud máte ve správní radě rozumnější lidi, tak tento řádek zakomentujte :-)
|
||
$this->create_transfer($operating, $parsed_acc,
|
||
abs($data->fee), $data->date_time, "Bank. poplatek hrazený sdružením",
|
||
$member->id, $id);
|
||
if ($member->id) { // našli jsme plátce?
|
||
// **** převedeme peníze členovi na jeho účet s kreditem
|
||
// ten účet ale musíme najít nebo vytvořit:
|
||
$credit_acc=$acc_model->find_by_member_id_and_account_attribute_id(
|
||
$member->id, Account_attribute_Model::$credit);
|
||
if (!$credit_acc->id) {
|
||
$credit_acc->clear();
|
||
$credit_acc->account_attribute_id = Account_attribute_Model::$credit;
|
||
$credit_acc->member_id = $member->id;
|
||
/**
|
||
* @todo Jirka pri tvorbe uctu jako jmeno uctu pouziva
|
||
* prijmeni jmeno majitele. To se mi tady nechce programovat,
|
||
* protoze se jen tezko muze stat, ze by kreditni ucet neexistoval
|
||
*/
|
||
$credit_acc->name = $member->name;
|
||
$credit_acc->save();
|
||
}
|
||
$this->create_transfer($parsed_acc, $acc_model,
|
||
$data->amount, $data->date_time, "Přiřazení platby",
|
||
$member->id, $id);
|
||
// **** teď se podíváme, jestli v té době sdružení účtovalo poplatek za zpracování platby:
|
||
$fee=$fee_model->get_by_date_type($data->date_time, 'transfer fee');
|
||
if (is_object($fee) && $fee->id) // ano? Pak poplatek strhneme z účtu
|
||
$this->create_transfer($credit_acc, $operating,
|
||
$fee->fee, $data->date_time, "Transakční poplatek",
|
||
$member->id, $id);
|
||
} // if (is_object($member) && $member->id)
|
||
$this->stats->member_fees_nr++;
|
||
$this->stats->member_fees+=$data->amount;
|
||
} // else { // $data->amount > 0
|
||
if ($term_vklad) { // převod peněz na účet term. vkladu
|
||
$id=$this->create_transfers($parsed_acc, $time_deposits, $amount,
|
||
$this->parsed_bank_acc, $bank_acc, $data, $member->id, null);
|
||
$this->stats->time_deposits_drawn+=$amount;
|
||
$this->stats->time_deposits_drawn_nr++;
|
||
} else {
|
||
// členský příspěvek - vytvoříme:
|
||
// - podvojnou transakci z 684000 na 221000
|
||
// - bankovní transakci z bank. účtu člena na bank. účet sdružení
|
||
$id=$this->create_transfers($member_fees, $parsed_acc, $data->amount,
|
||
$bank_acc, $this->parsed_bank_acc, $data, $member->id);
|
||
if (!empty($fee)) {
|
||
// bankovní poplatek - vytvoříme:
|
||
// - podvojnou transakci z 221000 (bank. účty) na 549001 (bank. poplatky)
|
||
// - bankovní transakci z parsovaného účtu na null
|
||
$data->comment = "Bank. poplatek". (!empty($data->comment) ? " ($data->comment)":"");
|
||
$this->create_transfers($parsed_acc, $bank_fees, $fee,
|
||
$this->parsed_bank_acc, null, $data, $member->id, $id);
|
||
// naše správní rada si vymyslela, že poplatek budeme dotovat z operačního účtu
|
||
// (pokud máte ve správní radě rozumnější lidi, tak tento řádek zakomentujte :-)
|
||
$this->create_transfer($operating, $parsed_acc,
|
||
abs($data->fee), $data->date_time, "Bank. poplatek hrazený sdružením",
|
||
$member->id, $id);
|
||
}
|
||
if ($member->id) { // původce je známý?
|
||
// **** převedeme peníze členovi na jeho účet s kreditem
|
||
// ten účet ale musíme najít nebo vytvořit:
|
||
$credit_acc=$acc_model->find_by_member_id_and_account_attribute_id(
|
||
$member->id, Account_attribute_Model::$credit);
|
||
if (!$credit_acc->id) {
|
||
$credit_acc->clear();
|
||
$credit_acc->account_attribute_id = Account_attribute_Model::$credit;
|
||
$credit_acc->member_id = $member->id;
|
||
/**
|
||
* @todo Jirka pri tvorbe uctu jako jmeno uctu pouziva
|
||
* prijmeni jmeno majitele. To se mi tady nechce programovat,
|
||
* protoze se jen tezko muze stat, ze by kreditni ucet neexistoval
|
||
*/
|
||
$credit_acc->name = $member->name;
|
||
$credit_acc->save();
|
||
}
|
||
$this->create_transfer($parsed_acc, $acc_model,
|
||
$data->amount, $data->date_time, "Přiřazení platby",
|
||
$member->id, $id);
|
||
// **** teď se podíváme, jestli v té době sdružení účtovalo poplatek za zpracování platby:
|
||
$fee=$fee_model->get_by_date_type($data->date_time, 'transfer fee');
|
||
if (is_object($fee) && $fee->id) // ano? Pak poplatek strhneme z účtu
|
||
$this->create_transfer($credit_acc, $operating,
|
||
$fee->fee, $data->date_time, "Transakční poplatek",
|
||
$member->id, $id);
|
||
} // if (is_object($member) && $member->id)
|
||
$this->stats->member_fees_nr++;
|
||
$this->stats->member_fees+=$data->amount;
|
||
} // if ($term_vklad) ... else {
|
||
} // else { // $data->amount > 0
|
||
} // else { // ****** castka!=0 && poplatek !=0
|
||
}
|
||
|
||
... | ... | |
$bank_transfer=new Bank_transfer_Model();
|
||
}
|
||
// nejdriv zkontroluj, jestli uz tuto transakci nemame od minuleho importu
|
||
if ($bank_transfer->exists($data)) throw new Duplicity_Exception();
|
||
$dups=$bank_transfer->get_duplicities($data);
|
||
if ($dups->count() > 0) throw new Duplicity_Exception($dups);
|
||
$transfer->clear();
|
||
$transfer->amount = $amount;
|
||
$transfer->datetime = $data->date_time;
|
||
... | ... | |
* @return void
|
||
*/
|
||
public function parse_ebank_account($bank_account_id=NULL, $url="") {
|
||
|
||
$parser=new Parser_Ebanka();
|
||
|
||
echo "Memory usage=".($mem=memory_get_usage()). "<p>\n";
|
||
... | ... | |
$parser->parse($url);
|
||
} catch (Duplicity_Exception $ex) {
|
||
// v případě duplicity commitujeme vše do výskytu duplicity a hned skončíme
|
||
echo "Duplicita!!!!";
|
||
echo "Končíme, právě importovaný záznam má již v databázi duplicitní záznam:<br/>\n";
|
||
echo "<table border=1>";
|
||
$first=true; $header="";
|
||
foreach ($ex->duplicity as $dup) {
|
||
echo "<tr>\n"; $data="";
|
||
foreach ($dup as $key=>$val) {
|
||
if ($first)
|
||
$header.="<th>$key</th>";
|
||
$data.="<td>$val</td>";
|
||
}
|
||
if ($first) {
|
||
echo $header;
|
||
echo "</tr>\n";
|
||
$first=false;
|
||
}
|
||
echo $data;
|
||
echo "</tr>\n";
|
||
}
|
||
}
|
||
//$parser->parse("http://localhost/2007.html");
|
||
//$parser->parse("c:/txt/unart/ucto/vypisy/2007/2007.html");
|
||
... | ... | |
foreach ($this->stats as $key=>$value)
|
||
echo "<tr><td>$key</td><td>$value</td></tr>";
|
||
echo "</table>\n";
|
||
echo "Memory usage=".(memory_get_usage()-$mem)."<p>\n";
|
||
if (!isset($this->stats->invoices)) $this->stats->invoices=0;
|
||
if (!isset($this->stats->interests)) $this->stats->interests=0;
|
||
if (!isset($this->stats->bank_fees)) $this->stats->bank_fees=0;
|
||
if (!isset($this->stats->member_fees)) $this->stats->member_fees=0;
|
||
|
||
echo "Bank. poplatky = ". $this->stats->bank_fees;
|
||
echo "<br/>\nVýdaje = ". ($this->stats->bank_fees + $this->stats->invoices);
|
||
echo "<br/>\nPříjmy = ". ($this->stats->interests + $this->stats->member_fees);
|
||
|
||
echo "<br/>\nMemory usage=".(memory_get_usage()-$mem)."<p>\n";
|
||
echo"parse - end: ".(microtime(true)-$start)."<p>\n";
|
||
//print_r($this);
|
||
//die("OK");
|
freenetis/trunk/kohana/application/libraries/Parser_Html_Table.php | ||
---|---|---|
protected function find_tag_and_trim($tag) {
|
||
$found=false;
|
||
do {
|
||
if (($pos=stripos($this->buffer, $tag))!==false) { // can you find the startag ?
|
||
if (($pos=stripos($this->buffer, $tag))!==false) { // can you find the tag ?
|
||
$found=true; // yes!
|
||
$pos+=strlen($tag); // set the cut $pos(ition) behind $tag
|
||
} else $pos=$this->eoln_pos; // no? Then set the cut $pos(ition) to the
|
||
// last eoln in buffer, so we don't have to deal with these lines again
|
||
// The last "non-terminated-yet" line (line without EOLN) must stay in the buffer!
|
||
$this->buffer=substr($this->buffer, $pos); // now cut away everything from the beginning till the cut position
|
||
// and update the counters
|
||
$this->eoln_pos -= $pos;
|
||
|
||
$pos+=strlen($tag); // set the cut $pos(ition) behind $tag
|
||
$this->buffer=substr($this->buffer, $pos); // now cut away everything from the beginning till the cut position
|
||
$this->eoln_pos -= $pos; // and update the counters
|
||
} else if ($this->eoln_pos>0) { // tag not found and eoln found previously?
|
||
$this->buffer=substr($this->buffer, $this->eoln_pos); // cut away all from beginning till eoln
|
||
$this->eoln_pos=0; //so we don't have to deal with these lines again
|
||
}
|
||
} while ( !$found && $this->get_line() );
|
||
|
||
return $found;
|
||
... | ... | |
if (($pos=stripos($this->buffer, $tag))!==false) { // can you find the startag ?
|
||
$found=true; // yes!
|
||
$pos+=strlen($tag); // set the cut $pos(ition) behind $tag
|
||
$this->buffer=substr($this->buffer, $pos); // now cut away everything from the beginning till the cut position
|
||
$this->eoln_pos -= $pos; // and update the counters
|
||
break;
|
||
} else $i++; // this tag not found - increment cntr and try another one
|
||
|
||
if (!$found) // no tag found at all?
|
||
$pos=$this->eoln_pos; // Then set the cut $pos(ition) to the
|
||
// last eoln in buffer, so we don't have to deal with these lines again
|
||
// The last "non-terminated-yet" line (line without EOLN) must stay in the buffer!
|
||
$this->buffer=substr($this->buffer, $pos); // now cut away everything from the beginning till the cut position
|
||
$this->eoln_pos -= $pos; // and update the counters
|
||
} else $i++; // this tag not found - increment cntr and try another one
|
||
if (!$found && $this->eoln_pos>0) { // tags not found and eoln found previously?
|
||
$this->buffer=substr($this->buffer, $this->eoln_pos); // cut away all from beginning till eoln
|
||
$this->eoln_pos=0;
|
||
}
|
||
} while ( !$found && $this->get_line() );
|
||
|
||
return $i;
|
||
}
|
||
/**
|
||
... | ... | |
*/
|
||
preg_match_all("/<td[^>]*>(?:<[^>]*>)?(.*?)<(?:(?:\/)?td|tr|table)/si", $rows, $this->matches);
|
||
$this->buffer=substr($this->buffer,$lastTagPos);
|
||
if ($this->eoln_pos>$lastTagPos)
|
||
$this->eoln_pos -= $lastTagPos;
|
||
else $this->eoln_pos = 0;
|
||
return true;
|
||
}
|
||
|
Také k dispozici: Unified diff
Tímto se pokazí import, nemám to ještě odladěné ale Jirka to po mně chce...