Version Notes
Sinta-se a vontade para contatar o suporte
Download this release
Release Info
| Developer | Raul Sakai |
| Extension | MoipExpress |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/local/Monstroestudio/Moip/Block/Form.php +185 -0
- app/code/local/Monstroestudio/Moip/Block/Redirect.php +158 -0
- app/code/local/Monstroestudio/Moip/Helper/Data.php +34 -0
- app/code/local/Monstroestudio/Moip/Model/Abstract.php +72 -0
- app/code/local/Monstroestudio/Moip/Model/Observer.php +324 -0
- app/code/local/Monstroestudio/Moip/Model/PaymentMethod.php +283 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Safe.php +32 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Safe/Collection.php +32 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Safe/Collection/Abstract.php +33 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Transactions.php +31 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Transactions/Collection.php +32 -0
- app/code/local/Monstroestudio/Moip/Model/Resource/Transactions/Collection/Abstract.php +33 -0
- app/code/local/Monstroestudio/Moip/Model/Safe.php +66 -0
- app/code/local/Monstroestudio/Moip/Model/Source/Ccmaxparcelas.php +44 -0
- app/code/local/Monstroestudio/Moip/Model/Source/Paymentmethods.php +34 -0
- app/code/local/Monstroestudio/Moip/Model/Source/Recebimento.php +33 -0
- app/code/local/Monstroestudio/Moip/Model/Source/Tipovencboleto.php +33 -0
- app/code/local/Monstroestudio/Moip/Model/Transactions.php +52 -0
- app/code/local/Monstroestudio/Moip/controllers/CheckoutController.php +186 -0
- app/code/local/Monstroestudio/Moip/etc/config.xml +178 -0
- app/code/local/Monstroestudio/Moip/etc/system.xml +201 -0
- app/code/local/Monstroestudio/Moip/sql/moip_setup/mysql4-install-1.0.0.php +252 -0
- app/design/frontend/default/default/layout/monstroestudio/moip.xml +37 -0
- app/design/frontend/default/default/template/monstroestudio/moip/form.phtml +160 -0
- app/design/frontend/default/default/template/monstroestudio/moip/redirect.phtml +117 -0
- lib/Moip/Moip.php +812 -0
- lib/Moip/MoipClient.php +131 -0
- lib/Moip/MoipEnvironment.php +12 -0
- lib/Moip/MoipResponse.php +26 -0
- lib/Moip/MoipStatus.php +83 -0
- lib/Moip/phpQuery/phpQuery.php +5702 -0
- package.xml +18 -0
- skin/frontend/default/default/monstroestudio/moip/css/styles.css +64 -0
- skin/frontend/default/default/monstroestudio/moip/images/amex.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/banrisul.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/bb.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/boleto.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/bradesco-boleto.jpg +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/bradesco.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/cc.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/diners.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/hiper.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/itau.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/master.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/moip-warning.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/printer.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/transf.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/transferencia-icon.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/images/visa.png +0 -0
- skin/frontend/default/default/monstroestudio/moip/js/creditcard.min.js +1 -0
- skin/frontend/default/default/monstroestudio/moip/js/jquery.js +5 -0
- skin/frontend/default/default/monstroestudio/moip/js/moip-form.js +211 -0
- skin/frontend/default/default/monstroestudio/moip/js/prototype.maskedinput.js +22 -0
- skin/frontend/default/default/monstroestudio/moip/js/validations.js +55 -0
app/code/local/Monstroestudio/Moip/Block/Form.php
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Block_Form extends Mage_Payment_Block_Form {
|
| 27 |
+
|
| 28 |
+
private $_helper;
|
| 29 |
+
private $_methods;
|
| 30 |
+
|
| 31 |
+
protected function _construct() {
|
| 32 |
+
$this->_helper = Mage::helper('moip');
|
| 33 |
+
$this->_methods = explode(',', $this->_helper->getConfig('methods'));
|
| 34 |
+
|
| 35 |
+
$this->setTemplate('monstroestudio/moip/form.phtml');
|
| 36 |
+
|
| 37 |
+
parent::_construct();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public function isCCAvailable() {
|
| 41 |
+
return in_array('cc', $this->_methods);
|
| 42 |
+
}
|
| 43 |
+
public function isBoletoAvailable() {
|
| 44 |
+
return in_array('boleto', $this->_methods);
|
| 45 |
+
}
|
| 46 |
+
public function isTransferenciaAvailable() {
|
| 47 |
+
return in_array('deposito', $this->_methods);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function isBoletoValidated(){
|
| 51 |
+
if(Mage::helper('moip')->getConfig('bloquear_boleto_estoque')){
|
| 52 |
+
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
| 53 |
+
$cartItems = $quote->getAllVisibleItems();
|
| 54 |
+
|
| 55 |
+
foreach($cartItems as $item){
|
| 56 |
+
if((int)Mage::getModel('cataloginventory/stock_item')->loadByProduct(Mage::getModel('catalog/product')->load($item->getProduct()->getId()))->getQty() <= (int)Mage::getStoreConfig('cataloginventory/item_options/notify_stock_qty')){
|
| 57 |
+
return false;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
return true;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
public function getMoipSafe() {
|
| 65 |
+
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
|
| 66 |
+
return $this->generateSafeOptions(Mage::getModel('moip/safe')->loadByCustomer(Mage::getSingleton('customer/session')->getCustomer()->getId()));
|
| 67 |
+
}else{
|
| 68 |
+
return false;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
protected function generateSafeOptions($collection){
|
| 73 |
+
if(count($collection)>0){
|
| 74 |
+
$html = '<option value="new">Novo cartão</option>';
|
| 75 |
+
foreach($collection as $item){
|
| 76 |
+
$html .= '<option value="'.$item->token.'" data-flag="'.$item->operator.'">**** **** **** '.$item->digits.'</option>';
|
| 77 |
+
}
|
| 78 |
+
return $html;
|
| 79 |
+
}
|
| 80 |
+
return false;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
public function getParcelamento() {
|
| 84 |
+
$orderTotal = $this->getQuote()->getGrandTotal();
|
| 85 |
+
$minParcela = (float)$this->_helper->getConfig('parcela_min');
|
| 86 |
+
$maxParcelas = (float)$this->_helper->getConfig('numero_max_parcelas');
|
| 87 |
+
$semJuros = (float)$this->_helper->getConfig('parcelas_s_juros');
|
| 88 |
+
|
| 89 |
+
$parcelas = array();
|
| 90 |
+
|
| 91 |
+
if(Mage::helper('moip')->getConfig('parcelado')){
|
| 92 |
+
if ($semJuros > 0 && ($orderTotal/$minParcela) > 1) {
|
| 93 |
+
|
| 94 |
+
if (($orderTotal/$minParcela) > $maxParcelas) {
|
| 95 |
+
for ($i = 0; $i < $semJuros; $i++) {
|
| 96 |
+
$parcelas[] = array('label' => ($i+1).' parcelas de '.Mage::helper('core')->currency(($orderTotal/($i+1)), true, false).' - Total: '.Mage::helper('core')->currency($orderTotal, true, false), 'value' => (int)$i+1);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
for ($i = $semJuros; $i < $maxParcelas; $i++) {
|
| 100 |
+
$parcelas[] = array('label' => ($i+1).' parcelas de '.$this->getValorParcelaLabel($orderTotal, ($i+1)).'*', 'value' => (int)$i+1);
|
| 101 |
+
}
|
| 102 |
+
}else {
|
| 103 |
+
for ($i = 0; $i < $semJuros; $i++) {
|
| 104 |
+
$parcelas[] = array('label' => ($i+1).' parcelas de '.Mage::helper('core')->currency(($orderTotal/($i+1)), true, false).' - Total: '.Mage::helper('core')->currency($orderTotal, true, false), 'value' => (int)$i+1);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
for ($i = $semJuros; $i < floor($this->getJurosComposto($orderTotal,$i)/$minParcela); $i++) {
|
| 108 |
+
$parcelas[] = array('label' => ($i+1).' parcelas de '.$this->getValorParcelaLabel($orderTotal, ($i+1)).'*', 'value' => (int)$i+1);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
}else{
|
| 113 |
+
$parcelas[] = array('label' => 'À vista', 'value' => 1);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
$html = '';
|
| 117 |
+
foreach ($parcelas as $parcela) {
|
| 118 |
+
$html .= '<option value="'.$parcela['value'].'">'.$parcela['label'].'</option>';
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return $html;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
public function getParcelasTexto() {
|
| 125 |
+
return 'Parcelas com "*" tem juros de'.str_replace('.', ',', $this->_helper->getConfig('juros_parcela')).'% ao mês';
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
public function getTextoDescontoBoleto() {
|
| 129 |
+
$desconto = (float)$this->_helper->getConfig('desconto_boleto');
|
| 130 |
+
if ($desconto > 0) {
|
| 131 |
+
return "<p class='desconto'>Desconto de $desconto% utilizando o Boleto Bancário como forma de pagamento</p>";
|
| 132 |
+
}
|
| 133 |
+
return;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
public function getTextoDescontoTransferencia() {
|
| 137 |
+
$desconto = (float)$this->_helper->getConfig('desconto_transf');
|
| 138 |
+
if ($desconto > 0) {
|
| 139 |
+
return "<p class='desconto'>Desconto de $desconto% utilizando a Transferência Bancária como forma de pagamento</p>";
|
| 140 |
+
}
|
| 141 |
+
return;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
protected function getValorParcela($valor, $parcelas) {
|
| 145 |
+
return Mage::helper('core')->currency($this->getJurosComposto($valor, $parcelas)/$parcelas, true, false);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
protected function getValorParcelaLabel($valor, $parcelas) {
|
| 149 |
+
return Mage::helper('core')->currency($this->getJurosComposto($valor, $parcelas)/$parcelas, true, false).' - Total: '.Mage::helper('core')->currency($this->getJurosComposto($valor, $parcelas), true, false);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
protected function getJurosComposto($valor, $parcelas) {
|
| 153 |
+
$juros = (float)$this->_helper->getConfig('juros_parcela')/100;
|
| 154 |
+
|
| 155 |
+
return round(($juros/(1-(1/pow((1+$juros),(int)$parcelas))))*$valor*(int)$parcelas,2);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Get checkout session namespace
|
| 160 |
+
*
|
| 161 |
+
* @return Mage_Checkout_Model_Session
|
| 162 |
+
*/
|
| 163 |
+
protected function getCheckout() {
|
| 164 |
+
return Mage::getSingleton('checkout/session');
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* Get current quote
|
| 169 |
+
*
|
| 170 |
+
* @return Mage_Sales_Model_Quote
|
| 171 |
+
*/
|
| 172 |
+
protected function getQuote() {
|
| 173 |
+
return $this->getCheckout()->getQuote();
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/**
|
| 177 |
+
* Get one page checkout model
|
| 178 |
+
*
|
| 179 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
| 180 |
+
*/
|
| 181 |
+
protected function getOnepage() {
|
| 182 |
+
return Mage::getSingleton('checkout/type_onepage');
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
}
|
app/code/local/Monstroestudio/Moip/Block/Redirect.php
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Block_Redirect extends Mage_Core_Block_Template {
|
| 27 |
+
|
| 28 |
+
private $_helper;
|
| 29 |
+
private $_salesData;
|
| 30 |
+
private $_order;
|
| 31 |
+
|
| 32 |
+
protected function _construct() {
|
| 33 |
+
parent::_construct();
|
| 34 |
+
$this->_helper = Mage::helper('moip');
|
| 35 |
+
$this->_salesData = $this->getCheckout()->getMoipData();
|
| 36 |
+
$this->_order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
|
| 37 |
+
Mage::register('current_order',$this->_order);
|
| 38 |
+
|
| 39 |
+
$this->setTemplate('monstroestudio/moip/redirect.phtml');
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
public function getPaymentMethod(){
|
| 43 |
+
return $this->_salesData['method'];
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
public function getShippingDescription(){
|
| 47 |
+
return $this->_order->getShippingDescription();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
public function getMoipJson(){
|
| 51 |
+
|
| 52 |
+
$json = array();
|
| 53 |
+
if($this->_salesData['method'] == 'cc' && $this->_salesData['moip_safe'] == 'new'){
|
| 54 |
+
$json['Forma'] = 'CartaoCredito';
|
| 55 |
+
$json['Instituicao'] = $this->getInstituicao($this->_salesData['bandeira']);
|
| 56 |
+
$json['Parcelas'] = $this->_salesData['parcelas'];
|
| 57 |
+
$json['CartaoCredito'] = array();
|
| 58 |
+
$json['CartaoCredito']['Numero'] = Mage::helper('core')->decrypt($this->_salesData['cc']);
|
| 59 |
+
$json['CartaoCredito']['Expiracao'] = $this->_salesData['validade'];
|
| 60 |
+
$json['CartaoCredito']['CodigoSeguranca'] = $this->_salesData['cvv'];
|
| 61 |
+
$json['CartaoCredito']['Portador'] = array();
|
| 62 |
+
$json['CartaoCredito']['Portador']['Nome'] = $this->_salesData['cc_holder_name'];
|
| 63 |
+
$json['CartaoCredito']['Portador']['DataNascimento'] = $this->_salesData['cc_holder_dob'];
|
| 64 |
+
$json['CartaoCredito']['Portador']['Telefone'] = $this->_salesData['cc_holder_phone'];
|
| 65 |
+
$json['CartaoCredito']['Portador']['Identidade'] = $this->_salesData['cc_holder_cpf'];
|
| 66 |
+
}elseif($this->_salesData['method'] == 'cc' && $this->_salesData['moip_safe'] != 'new'){
|
| 67 |
+
$json['Forma'] = 'CartaoCredito';
|
| 68 |
+
$json['Instituicao'] = $this->getInstituicao($this->_salesData['bandeira']);
|
| 69 |
+
$json['Parcelas'] = $this->_salesData['safe_parcelas'];
|
| 70 |
+
$json['CartaoCredito'] = array();
|
| 71 |
+
$json['CartaoCredito']['Cofre'] = $this->_salesData['moip_safe'];
|
| 72 |
+
$json['CartaoCredito']['CodigoSeguranca'] = $this->_salesData['safe_cvv'];
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if($this->_salesData['method'] == 'boleto'){
|
| 78 |
+
$json['Forma'] = 'BoletoBancario';
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if($this->_salesData['method'] == 'transferencia'){
|
| 82 |
+
$json['Forma'] = 'DebitoBancario';
|
| 83 |
+
$json['Instituicao'] = $this->_salesData['bandeira'];
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
//erase credit card data
|
| 87 |
+
$this->getCheckout()->setMoipData('');
|
| 88 |
+
|
| 89 |
+
return json_encode($json);
|
| 90 |
+
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
public function getMoipUrl(){
|
| 94 |
+
if ((bool)$this->_helper->getConfig('test')) {
|
| 95 |
+
return "https://desenvolvedor.moip.com.br/sandbox";
|
| 96 |
+
}
|
| 97 |
+
return "https://www.moip.com.br/";
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
public function getToken(){
|
| 101 |
+
return Mage::getModel('moip/transactions')->loadByOrder($this->getOrderId())->token;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
public function getOrderId(){
|
| 105 |
+
return $this->getCheckout()->getLastRealOrderId();
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Get checkout session namespace
|
| 110 |
+
*
|
| 111 |
+
* @return Mage_Checkout_Model_Session
|
| 112 |
+
*/
|
| 113 |
+
protected function getCheckout()
|
| 114 |
+
{
|
| 115 |
+
return Mage::getSingleton('checkout/session');
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/**
|
| 119 |
+
* Get current quote
|
| 120 |
+
*
|
| 121 |
+
* @return Mage_Sales_Model_Quote
|
| 122 |
+
*/
|
| 123 |
+
protected function getQuote()
|
| 124 |
+
{
|
| 125 |
+
return $this->getCheckout()->getQuote();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* Get one page checkout model
|
| 130 |
+
*
|
| 131 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
| 132 |
+
*/
|
| 133 |
+
protected function getOnepage()
|
| 134 |
+
{
|
| 135 |
+
return Mage::getSingleton('checkout/type_onepage');
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
protected function getInstituicao($string){
|
| 139 |
+
switch($string){
|
| 140 |
+
case 'amex':
|
| 141 |
+
return 'AmericanExpress';
|
| 142 |
+
break;
|
| 143 |
+
case 'diners':
|
| 144 |
+
return 'Diners';
|
| 145 |
+
break;
|
| 146 |
+
case 'master':
|
| 147 |
+
return 'Mastercard';
|
| 148 |
+
break;
|
| 149 |
+
case 'hiper':
|
| 150 |
+
return 'Hipercard';
|
| 151 |
+
break;
|
| 152 |
+
case 'visa':
|
| 153 |
+
return 'Visa';
|
| 154 |
+
break;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
}
|
app/code/local/Monstroestudio/Moip/Helper/Data.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Helper_Data extends Mage_Core_Helper_Abstract{
|
| 27 |
+
public function getConfig($config){
|
| 28 |
+
return Mage::getStoreConfig('payment/moip/'.$config);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
public function isActive(){
|
| 32 |
+
return (bool)Mage::getStoreConfig('payment/moip/active');
|
| 33 |
+
}
|
| 34 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Abstract.php
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
abstract class Monstroestudio_Moip_Model_Abstract extends Mage_Core_Model_Abstract
|
| 27 |
+
{
|
| 28 |
+
/**
|
| 29 |
+
* Store rule combine conditions model
|
| 30 |
+
*
|
| 31 |
+
* @var Mage_Rule_Model_Condition_Combine
|
| 32 |
+
*/
|
| 33 |
+
protected $_conditions;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Store rule form instance
|
| 37 |
+
*
|
| 38 |
+
* @var Varien_Data_Form
|
| 39 |
+
*/
|
| 40 |
+
protected $_form;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Is model can be deleted flag
|
| 44 |
+
*
|
| 45 |
+
* @var bool
|
| 46 |
+
*/
|
| 47 |
+
protected $_isDeleteable = true;
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Is model readonly
|
| 51 |
+
*
|
| 52 |
+
* @var bool
|
| 53 |
+
*/
|
| 54 |
+
protected $_isReadonly = false;
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Prepare data before saving
|
| 59 |
+
*
|
| 60 |
+
* @return Mage_Rule_Model_Abstract
|
| 61 |
+
*/
|
| 62 |
+
protected function _beforeSave()
|
| 63 |
+
{
|
| 64 |
+
parent::_beforeSave();
|
| 65 |
+
return $this;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
protected function _prepareWebsiteIds()
|
| 69 |
+
{
|
| 70 |
+
return $this;
|
| 71 |
+
}
|
| 72 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Observer.php
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Observer{
|
| 27 |
+
public function updateStreetLines($observer){
|
| 28 |
+
if(Mage::helper('moip')->isActive()){
|
| 29 |
+
$model = new Mage_Core_Model_Config();
|
| 30 |
+
$model->saveConfig('customer/address/street_lines', "4", 'default', 0);
|
| 31 |
+
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public function setDiscount($observer) {
|
| 36 |
+
$type = false;
|
| 37 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'boleto'){
|
| 38 |
+
$type = 'boleto';
|
| 39 |
+
}else if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'transferencia'){
|
| 40 |
+
$type = 'transf';
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
$quote=$observer->getEvent()->getQuote();
|
| 44 |
+
|
| 45 |
+
if(!$quote || !$type){
|
| 46 |
+
return false;
|
| 47 |
+
}
|
| 48 |
+
$quoteid = $quote->getId();
|
| 49 |
+
|
| 50 |
+
if($type == 'boleto'){
|
| 51 |
+
$descTitle = 'Boleto';
|
| 52 |
+
}else{
|
| 53 |
+
$descTitle = 'Transferência Bancária';
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if ($quoteid && (float)Mage::helper('moip')->getConfig('desconto_'.$type) > 0) {
|
| 57 |
+
$discountAmount = ((float)Mage::helper('moip')->getConfig('desconto_'.$type)/100)*$quote->getBaseSubtotal();
|
| 58 |
+
|
| 59 |
+
if ($discountAmount>0) {
|
| 60 |
+
$total=$quote->getBaseSubtotal();
|
| 61 |
+
$quote->setSubtotal(0);
|
| 62 |
+
$quote->setBaseSubtotal(0);
|
| 63 |
+
|
| 64 |
+
$quote->setSubtotalWithDiscount(0);
|
| 65 |
+
$quote->setBaseSubtotalWithDiscount(0);
|
| 66 |
+
|
| 67 |
+
$quote->setGrandTotal(0);
|
| 68 |
+
$quote->setBaseGrandTotal(0);
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
$canAddItems = $quote->isVirtual()? ('billing') : ('shipping');
|
| 72 |
+
foreach ($quote->getAllAddresses() as $address) {
|
| 73 |
+
|
| 74 |
+
$address->setSubtotal(0);
|
| 75 |
+
$address->setBaseSubtotal(0);
|
| 76 |
+
|
| 77 |
+
$address->setGrandTotal(0);
|
| 78 |
+
$address->setBaseGrandTotal(0);
|
| 79 |
+
|
| 80 |
+
$address->collectTotals();
|
| 81 |
+
|
| 82 |
+
$quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
|
| 83 |
+
$quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
|
| 84 |
+
|
| 85 |
+
$quote->setSubtotalWithDiscount((float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount());
|
| 86 |
+
$quote->setBaseSubtotalWithDiscount((float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount());
|
| 87 |
+
|
| 88 |
+
$quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
|
| 89 |
+
$quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
|
| 90 |
+
|
| 91 |
+
$quote->save();
|
| 92 |
+
|
| 93 |
+
$quote->setGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
| 94 |
+
->setBaseGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
| 95 |
+
->setSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
| 96 |
+
->setBaseSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
| 97 |
+
->save();
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
if ($address->getAddressType()==$canAddItems) {
|
| 101 |
+
$address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount()-$discountAmount);
|
| 102 |
+
$address->setGrandTotal((float) $address->getGrandTotal()-$discountAmount);
|
| 103 |
+
$address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount()-$discountAmount);
|
| 104 |
+
$address->setBaseGrandTotal((float) $address->getBaseGrandTotal()-$discountAmount);
|
| 105 |
+
if ($address->getDiscountDescription()) {
|
| 106 |
+
$address->setDiscountAmount(-($address->getDiscountAmount()-$discountAmount));
|
| 107 |
+
$address->setDiscountDescription($address->getDiscountDescription().', Desconto '.$descTitle.': '.Mage::helper('moip')->getConfig('desconto_boleto').'%');
|
| 108 |
+
$address->setBaseDiscountAmount(-($address->getBaseDiscountAmount()-$discountAmount));
|
| 109 |
+
}else {
|
| 110 |
+
$address->setDiscountAmount(-($discountAmount));
|
| 111 |
+
$address->setDiscountDescription('Desconto '.$descTitle.': '.Mage::helper('moip')->getConfig('desconto_'.$type).'%');
|
| 112 |
+
$address->setBaseDiscountAmount(-($discountAmount));
|
| 113 |
+
}
|
| 114 |
+
$address->save();
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
foreach ($quote->getAllItems() as $item) {
|
| 119 |
+
//We apply discount amount based on the ratio between the GrandTotal and the RowTotal
|
| 120 |
+
$rat=$item->getPriceInclTax()/$total;
|
| 121 |
+
$ratdisc=$discountAmount*$rat;
|
| 122 |
+
$item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
|
| 123 |
+
$item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
|
| 124 |
+
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
public function setCCTax($observer) {
|
| 131 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'cc' && $this->getOnepage()->getQuote()->getPayment()->getParcelas() > (float)Mage::helper('moip')->getConfig('parcelas_s_juros') ){
|
| 132 |
+
$quote=$observer->getEvent()->getQuote();
|
| 133 |
+
if(!$quote){
|
| 134 |
+
return false;
|
| 135 |
+
}
|
| 136 |
+
$quoteid = $quote->getId();
|
| 137 |
+
|
| 138 |
+
if ($quoteid) {
|
| 139 |
+
$discountAmount = -($this->getJurosComposto($quote->getGrandTotal(), (int)$this->getOnepage()->getQuote()->getPayment()->getParcelas()) - $quote->getGrandTotal());
|
| 140 |
+
|
| 141 |
+
if ($discountAmount<0) {
|
| 142 |
+
$total=$quote->getBaseSubtotal();
|
| 143 |
+
$quote->setSubtotal(0);
|
| 144 |
+
$quote->setBaseSubtotal(0);
|
| 145 |
+
|
| 146 |
+
$quote->setSubtotalWithDiscount(0);
|
| 147 |
+
$quote->setBaseSubtotalWithDiscount(0);
|
| 148 |
+
|
| 149 |
+
$quote->setGrandTotal(0);
|
| 150 |
+
$quote->setBaseGrandTotal(0);
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
$canAddItems = $quote->isVirtual()? ('billing') : ('shipping');
|
| 154 |
+
foreach ($quote->getAllAddresses() as $address) {
|
| 155 |
+
|
| 156 |
+
$address->setSubtotal(0);
|
| 157 |
+
$address->setBaseSubtotal(0);
|
| 158 |
+
|
| 159 |
+
$address->setGrandTotal(0);
|
| 160 |
+
$address->setBaseGrandTotal(0);
|
| 161 |
+
|
| 162 |
+
$address->collectTotals();
|
| 163 |
+
|
| 164 |
+
$quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
|
| 165 |
+
$quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
|
| 166 |
+
|
| 167 |
+
$quote->setSubtotalWithDiscount((float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount());
|
| 168 |
+
$quote->setBaseSubtotalWithDiscount((float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount());
|
| 169 |
+
|
| 170 |
+
$quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
|
| 171 |
+
$quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
|
| 172 |
+
|
| 173 |
+
$quote->save();
|
| 174 |
+
|
| 175 |
+
$quote->setGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
| 176 |
+
->setBaseGrandTotal($quote->getBaseSubtotal()-$discountAmount)
|
| 177 |
+
->setSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
| 178 |
+
->setBaseSubtotalWithDiscount($quote->getBaseSubtotal()-$discountAmount)
|
| 179 |
+
->save();
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
if ($address->getAddressType()==$canAddItems) {
|
| 183 |
+
$address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount()-$discountAmount);
|
| 184 |
+
$address->setGrandTotal((float) $address->getGrandTotal()-$discountAmount);
|
| 185 |
+
$address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount()-$discountAmount);
|
| 186 |
+
$address->setBaseGrandTotal((float) $address->getBaseGrandTotal()-$discountAmount);
|
| 187 |
+
if ($address->getDiscountDescription()) {
|
| 188 |
+
$address->setDiscountAmount(-($address->getDiscountAmount()-$discountAmount));
|
| 189 |
+
$address->setDiscountDescription($address->getDiscountDescription().', Juros de parcelas do cartão de crédito');
|
| 190 |
+
$address->setBaseDiscountAmount(-($address->getBaseDiscountAmount()-$discountAmount));
|
| 191 |
+
}else {
|
| 192 |
+
$address->setDiscountAmount(-($discountAmount));
|
| 193 |
+
$address->setDiscountDescription('Juros de parcelas do cartão de crédito');
|
| 194 |
+
$address->setBaseDiscountAmount(-($discountAmount));
|
| 195 |
+
}
|
| 196 |
+
$address->save();
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
foreach ($quote->getAllItems() as $item) {
|
| 201 |
+
//We apply discount amount based on the ratio between the GrandTotal and the RowTotal
|
| 202 |
+
$rat=$item->getPriceInclTax()/$total;
|
| 203 |
+
$ratdisc=$discountAmount*$rat;
|
| 204 |
+
$item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
|
| 205 |
+
$item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
|
| 206 |
+
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/*public function setCCTax($observer){
|
| 214 |
+
|
| 215 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'cc' && $this->getOnepage()->getQuote()->getPayment()->getParcelas() > (float)Mage::helper('moip')->getConfig('parcelas_s_juros') ){
|
| 216 |
+
$quote=$observer->getEvent()->getQuote();
|
| 217 |
+
$TaxAmount = $this->getJurosComposto($quote->getGrandTotal(), (int)$this->getOnepage()->getQuote()->getPayment()->getParcelas()) - $quote->getGrandTotal();
|
| 218 |
+
Mage::log($TaxAmount);
|
| 219 |
+
if ($TaxAmount) {
|
| 220 |
+
$total=$quote->getBaseSubtotal();
|
| 221 |
+
$quote->setSubtotal(0);
|
| 222 |
+
$quote->setBaseSubtotal(0);
|
| 223 |
+
|
| 224 |
+
$quote->setSubtotalWithTax(0);
|
| 225 |
+
$quote->setBaseSubtotalWithTax(0);
|
| 226 |
+
|
| 227 |
+
$quote->setGrandTotal(0);
|
| 228 |
+
$quote->setBaseGrandTotal(0);
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
$canAddItems = $quote->isVirtual()? ('billing') : ('shipping');
|
| 232 |
+
foreach ($quote->getAllAddresses() as $address) {
|
| 233 |
+
|
| 234 |
+
$address->setSubtotal(0);
|
| 235 |
+
$address->setBaseSubtotal(0);
|
| 236 |
+
|
| 237 |
+
$address->setGrandTotal(0);
|
| 238 |
+
$address->setBaseGrandTotal(0);
|
| 239 |
+
|
| 240 |
+
$address->collectTotals();
|
| 241 |
+
|
| 242 |
+
$quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
|
| 243 |
+
$quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
|
| 244 |
+
|
| 245 |
+
$quote->setSubtotalWithTax((float) $quote->getSubtotalWithTax() + $address->getSubtotalWithTax());
|
| 246 |
+
$quote->setBaseSubtotalWithTax((float) $quote->getBaseSubtotalWithTax() + $address->getBaseSubtotalWithTax());
|
| 247 |
+
|
| 248 |
+
$quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
|
| 249 |
+
$quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
|
| 250 |
+
|
| 251 |
+
$quote->save();
|
| 252 |
+
|
| 253 |
+
$quote->setGrandTotal($quote->getBaseSubtotal()+$TaxAmount)
|
| 254 |
+
->setBaseGrandTotal($quote->getBaseSubtotal()+$TaxAmount)
|
| 255 |
+
->setSubtotalWithTax($quote->getBaseSubtotal()+$TaxAmount)
|
| 256 |
+
->setBaseSubtotalWithTax($quote->getBaseSubtotal()+$TaxAmount)
|
| 257 |
+
->save();
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
if ($address->getAddressType()==$canAddItems) {
|
| 261 |
+
$address->setSubtotalWithTax((float) $address->getSubtotalWithTax()+$TaxAmount);
|
| 262 |
+
$address->setGrandTotal((float) $address->getGrandTotal()+$TaxAmount);
|
| 263 |
+
$address->setBaseSubtotalWithTax((float) $address->getBaseSubtotalWithTax()+$TaxAmount);
|
| 264 |
+
$address->setBaseGrandTotal((float) $address->getBaseGrandTotal()+$TaxAmount);
|
| 265 |
+
if ($address->getTaxDescription()) {
|
| 266 |
+
$address->setTaxAmount($address->getTaxAmount()-$TaxAmount);
|
| 267 |
+
$address->setTaxDescription('Juros de parcelamento do cartão');
|
| 268 |
+
$address->setBaseTaxAmount($address->getBaseTaxAmount()-$TaxAmount);
|
| 269 |
+
}else {
|
| 270 |
+
$address->setTaxAmount($TaxAmount);
|
| 271 |
+
$address->setTaxDescription('Juros do cartão de crédito');
|
| 272 |
+
$address->setBaseTaxAmount($TaxAmount);
|
| 273 |
+
}
|
| 274 |
+
$address->save();
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
foreach ($quote->getAllItems() as $item) {
|
| 279 |
+
//We apply Tax amount based on the ratio between the GrandTotal and the RowTotal
|
| 280 |
+
$rat=$item->getPriceInclTax()/$total;
|
| 281 |
+
$ratdisc=$TaxAmount*$rat;
|
| 282 |
+
$item->setTaxAmount(($item->getTaxAmount()+$ratdisc) * $item->getQty());
|
| 283 |
+
$item->setBaseTaxAmount(($item->getBaseTaxAmount()+$ratdisc) * $item->getQty())->save();
|
| 284 |
+
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
}
|
| 289 |
+
}*/
|
| 290 |
+
|
| 291 |
+
protected function getJurosComposto($valor, $parcelas) {
|
| 292 |
+
$juros = (float)Mage::helper('moip')->getConfig('juros_parcela')/100;
|
| 293 |
+
|
| 294 |
+
return ($juros/(1-(1/pow((1+$juros),(int)$parcelas))))*$valor*(int)$parcelas;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
/**
|
| 299 |
+
* Get checkout session namespace
|
| 300 |
+
*
|
| 301 |
+
* @return Mage_Checkout_Model_Session
|
| 302 |
+
*/
|
| 303 |
+
public function getCheckout() {
|
| 304 |
+
return Mage::getSingleton('checkout/session');
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/**
|
| 308 |
+
* Get current quote
|
| 309 |
+
*
|
| 310 |
+
* @return Mage_Sales_Model_Quote
|
| 311 |
+
*/
|
| 312 |
+
public function getQuote() {
|
| 313 |
+
return $this->getCheckout()->getQuote();
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Get one page checkout model
|
| 318 |
+
*
|
| 319 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
| 320 |
+
*/
|
| 321 |
+
public function getOnepage() {
|
| 322 |
+
return Mage::getSingleton('checkout/type_onepage');
|
| 323 |
+
}
|
| 324 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/PaymentMethod.php
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
|
| 27 |
+
{
|
| 28 |
+
|
| 29 |
+
private $_token = 'VUVRIGGW9A7UM6DPAHOFKAOKSZLREDFB';
|
| 30 |
+
private $_key = 'FIAFGINNFLYFMUDLNUJVEMIIVVIHADJAW3ARLXT8';
|
| 31 |
+
private $_tokenHomolog = 'CC0IIN6QXYPXTYNRS5VKFNVHKD2F76W1';
|
| 32 |
+
private $_keyHomolog = 'SUI72I2JBVJUCCZHCJRUSEFJBBBCE9UVTCBWCTM2';
|
| 33 |
+
private $_moip;
|
| 34 |
+
|
| 35 |
+
protected $_code = 'moip';
|
| 36 |
+
protected $_isGateway = true;
|
| 37 |
+
protected $_canAuthorize = true;
|
| 38 |
+
protected $_canCapture = true;
|
| 39 |
+
protected $_canCapturePartial = true;
|
| 40 |
+
protected $_canRefund = true;
|
| 41 |
+
protected $_canVoid = true;
|
| 42 |
+
protected $_canUseInternal = true;
|
| 43 |
+
protected $_canUseCheckout = true;
|
| 44 |
+
protected $_canUseForMultishipping = true;
|
| 45 |
+
protected $_canSaveCc = false;
|
| 46 |
+
protected $_formBlockType = 'moip/form';
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Send authorize request to gateway
|
| 50 |
+
*
|
| 51 |
+
* @param Mage_Payment_Model_Info $payment
|
| 52 |
+
* @param decimal $amount
|
| 53 |
+
* @return Monstroestudio_Moip_Model_PaymentMethod
|
| 54 |
+
*/
|
| 55 |
+
public function authorize(Varien_Object $payment, $amount) {
|
| 56 |
+
if ($amount <= 0) {
|
| 57 |
+
Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorization.'));
|
| 58 |
+
}
|
| 59 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'cc'){
|
| 60 |
+
if(Mage::helper('moip')->getConfig('parcelado') && (float)Mage::helper('moip')->getConfig('parcelas_s_juros') < (int)$this->getOnepage()->getQuote()->getPayment()->getParcelas()){
|
| 61 |
+
$amount = round($this->removeJurosComposto($amount, (int)$this->getOnepage()->getQuote()->getPayment()->getParcelas()),2);
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
$this->_moip = new Moip_Moip();
|
| 66 |
+
|
| 67 |
+
$this->_moip->setEnvironment((bool)Mage::helper('moip')->getConfig('test'));
|
| 68 |
+
|
| 69 |
+
if((bool)Mage::helper('moip')->getConfig('test')){
|
| 70 |
+
$this->_moip->setCredential(array(
|
| 71 |
+
'key' => $this->_keyHomolog,
|
| 72 |
+
'token' => $this->_tokenHomolog
|
| 73 |
+
));
|
| 74 |
+
}else{
|
| 75 |
+
$this->_moip->setCredential(array(
|
| 76 |
+
'key' => $this->_key,
|
| 77 |
+
'token' => $this->_token
|
| 78 |
+
));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
$billing = $this->getQuote()->getBillingAddress();
|
| 82 |
+
$street = $billing->getStreet();
|
| 83 |
+
$this->_moip->setUniqueID(Mage::app()->getStore()->getName().$payment->getOrder()->getIncrementId());
|
| 84 |
+
$this->_moip->setValue("$amount");
|
| 85 |
+
$this->_moip->setReason('Compra na loja '.Mage::app()->getStore()->getName());
|
| 86 |
+
$this->_moip->setPayer(array(
|
| 87 |
+
'name' => $payment->getOrder()->getCustomerFirstname().' '.$payment->getOrder()->getCustomerLastname(),
|
| 88 |
+
'email' => $payment->getOrder()->getCustomerEmail(),
|
| 89 |
+
'payerId' => $payment->getOrder()->getCustomerId(),
|
| 90 |
+
'billingAddress' => array(
|
| 91 |
+
'address' => $street[0],
|
| 92 |
+
'number' => $street[1],
|
| 93 |
+
'complement' => $street[2],
|
| 94 |
+
'neighborhood' => $street[3],
|
| 95 |
+
'city' => $billing->getCity(),
|
| 96 |
+
'state' => $billing->getRegionCode(),
|
| 97 |
+
'country' => $billing->getCountryId(),
|
| 98 |
+
'zipCode' => $billing->getPostcode(),
|
| 99 |
+
'phone' => $billing->getTelephone()
|
| 100 |
+
)));
|
| 101 |
+
|
| 102 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'boleto'){
|
| 103 |
+
$this->_moip->addPaymentWay('billet');
|
| 104 |
+
if(Mage::getStoreConfig('design/theme/default') !== ''){
|
| 105 |
+
$theme = '/'.Mage::getStoreConfig('design/theme/default').'/';
|
| 106 |
+
}else{
|
| 107 |
+
$theme = '/default/';
|
| 108 |
+
}
|
| 109 |
+
$this->_moip->setBilletConf(Mage::helper('moip')->getConfig('vencimento_boleto'), Mage::helper('moip')->getConfig('tipo_vencimento_boleto'), explode("\n", utf8_decode(Mage::helper('moip')->getConfig('instrucao_boleto'))), Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/'.Mage::getStoreConfig('design/package/name').$theme.Mage::getStoreConfig('design/header/logo_src'));
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if($this->getOnepage()->getQuote()->getPayment()->getMoipMethod() == 'cc' && Mage::helper('moip')->getConfig('parcelado')){
|
| 113 |
+
if((int)$this->getOnepage()->getQuote()->getPayment()->getParcelas() > (int)Mage::helper('moip')->getConfig('parcelas_s_juros')){
|
| 114 |
+
$this->_moip->addParcel(((int)Mage::helper('moip')->getConfig('parcelas_s_juros')+1), (int)Mage::helper('moip')->getConfig('numero_max_parcelas'), (float)Mage::helper('moip')->getConfig('juros_parcela'), false, ((bool)Mage::helper('moip')->getConfig('parcelado')?'AVista':'Parcelado'));
|
| 115 |
+
}else{
|
| 116 |
+
$this->_moip->addParcel('1', Mage::helper('moip')->getConfig('parcelas_s_juros'),0,false,((bool)Mage::helper('moip')->getConfig('parcelado')?'AVista':'Parcelado'));
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
$this->_moip->setReceiver(Mage::helper('moip')->getConfig('login'), Mage::app()->getStore()->getName());
|
| 121 |
+
$this->_moip->setNotificationURL(Mage::getUrl('moip/checkout/update'));
|
| 122 |
+
$this->_moip->validate('Identification');
|
| 123 |
+
|
| 124 |
+
$this->_moip->send();
|
| 125 |
+
|
| 126 |
+
$this->getCheckout()->setMoipData(array(
|
| 127 |
+
'method'=> $this->getOnepage()->getQuote()->getPayment()->getMoipMethod(),
|
| 128 |
+
'cc' => Mage::helper('core')->encrypt($this->getOnepage()->getQuote()->getPayment()->getCcNumber()),
|
| 129 |
+
'bandeira' => $this->getOnepage()->getQuote()->getPayment()->getBandeira(),
|
| 130 |
+
'validade' => $this->getOnepage()->getQuote()->getPayment()->getValidade(),
|
| 131 |
+
'parcelas' => $this->getOnepage()->getQuote()->getPayment()->getParcelas(),
|
| 132 |
+
'cvv' => $this->getOnepage()->getQuote()->getPayment()->getCvv(),
|
| 133 |
+
'safe_cvv' => $this->getOnepage()->getQuote()->getPayment()->getSafeCvv(),
|
| 134 |
+
'safe_parcelas' => $this->getOnepage()->getQuote()->getPayment()->getSafeParcelas(),
|
| 135 |
+
'moip_safe' => $this->getOnepage()->getQuote()->getPayment()->getMoipSafe(),
|
| 136 |
+
'cc_holder_name' => $this->getOnepage()->getQuote()->getPayment()->getCreditcardHolderName(),
|
| 137 |
+
'cc_holder_cpf' => $this->getOnepage()->getQuote()->getPayment()->getCcHolderCpf(),
|
| 138 |
+
'cc_holder_dob' => $this->getOnepage()->getQuote()->getPayment()->getCcHolderDob(),
|
| 139 |
+
'cc_holder_phone' => $this->getOnepage()->getQuote()->getPayment()->getCcHolderPhone(),
|
| 140 |
+
'save_cc' => $this->getOnepage()->getQuote()->getPayment()->getCcSave(),
|
| 141 |
+
));
|
| 142 |
+
|
| 143 |
+
if(isset($this->_moip->getAnswer()->error)){
|
| 144 |
+
$idAlreadyExists = $this->_moip->getAnswer()->error == 'Id Próprio já foi utilizado em outra Instrução';
|
| 145 |
+
}else{
|
| 146 |
+
$idAlreadyExists = false;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if ((bool)$this->_moip->getAnswer()->response || $idAlreadyExists) {
|
| 150 |
+
if(!$idAlreadyExists){
|
| 151 |
+
$arrayData = array(
|
| 152 |
+
'order_id' => (int)$payment->getOrder()->getIncrementId(),
|
| 153 |
+
'token' => $this->_moip->getAnswer()->token,
|
| 154 |
+
'accept_safe' => $this->getOnepage()->getQuote()->getPayment()->getCcSave(),
|
| 155 |
+
'data' => serialize($this->_moip->getAnswer())
|
| 156 |
+
);
|
| 157 |
+
$modelResponse = Mage::getModel('moip/transactions')->setData($arrayData)->save();
|
| 158 |
+
}
|
| 159 |
+
}else {
|
| 160 |
+
Mage::throwException(Mage::helper('moip')->__($this->_moip->getAnswer()->error));
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
return $this;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
protected function removeJurosComposto($valor, $parcelas) {
|
| 167 |
+
$juros = (float)Mage::helper('moip')->getConfig('juros_parcela')/100;
|
| 168 |
+
|
| 169 |
+
return $valor/$parcelas/($juros/(1-(1/pow((1+$juros),(int)$parcelas))));
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Void the payment through gateway
|
| 174 |
+
*
|
| 175 |
+
* @param Mage_Payment_Model_Info $payment
|
| 176 |
+
* @return Monstroestudio_Moip_Model_PaymentMethod
|
| 177 |
+
*/
|
| 178 |
+
public function void(Varien_Object $payment) {
|
| 179 |
+
$cardsStorage = $this->getCardsStorage($payment);
|
| 180 |
+
|
| 181 |
+
$messages = array();
|
| 182 |
+
$isSuccessful = false;
|
| 183 |
+
$isFiled = false;
|
| 184 |
+
|
| 185 |
+
return $this;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* Change redirect Url
|
| 190 |
+
*
|
| 191 |
+
* @return string
|
| 192 |
+
*/
|
| 193 |
+
public function getOrderPlaceRedirectUrl() {
|
| 194 |
+
//when you click on place order you will be redirected on this url, if you don't want this action remove this method
|
| 195 |
+
return Mage::getUrl('moip/checkout/authorize', array('_secure' => true));
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* Checkout redirect URL getter
|
| 200 |
+
*
|
| 201 |
+
* @return string
|
| 202 |
+
*/
|
| 203 |
+
public function getCheckoutRedirectUrl()
|
| 204 |
+
{
|
| 205 |
+
|
| 206 |
+
$method = $this->getMethodInstance();
|
| 207 |
+
if ($method) {
|
| 208 |
+
return $method->getCheckoutRedirectUrl();
|
| 209 |
+
}
|
| 210 |
+
return '';
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
public function assignData($data) {
|
| 214 |
+
if (!($data instanceof Varien_Object)) {
|
| 215 |
+
$data = new Varien_Object($data);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
$info = $this->getInfoInstance();
|
| 219 |
+
$info->setMoipMethod($data->getMoipMethod())
|
| 220 |
+
->setCcNumber($data->getCcNumber())
|
| 221 |
+
->setBandeira($data->getBandeira())
|
| 222 |
+
->setValidade($data->getValidade())
|
| 223 |
+
->setCreditcardHolderName($data->getCreditcardHolderName())
|
| 224 |
+
->setCvv($data->getCvv())
|
| 225 |
+
->setSafeCvv($data->getSafeCvv())
|
| 226 |
+
->setParcelas($data->getParcelas())
|
| 227 |
+
->setCcHolderCpf($data->getCcHolderCpf())
|
| 228 |
+
->setMoipSafe($data->getMoipSafe())
|
| 229 |
+
->setCcHolderDob($data->getCcHolderDob())
|
| 230 |
+
->setCcHolderPhone($data->getCcHolderPhone())
|
| 231 |
+
->setCcSave($data->getCcSave());
|
| 232 |
+
|
| 233 |
+
Mage::dispatchEvent('moip_sales_quote_assign_data_after', array('quote'=>$this->getOnepage()->getQuote()));
|
| 234 |
+
|
| 235 |
+
return $this;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
public function validate() {
|
| 240 |
+
parent::validate();
|
| 241 |
+
|
| 242 |
+
$info = $this->getInfoInstance();
|
| 243 |
+
|
| 244 |
+
/*$no = $info->getCheckNo();
|
| 245 |
+
$date = $info->getCheckDate();
|
| 246 |
+
if (empty($no) || empty($date)) {
|
| 247 |
+
$errorCode = 'invalid_data';
|
| 248 |
+
$errorMsg = $this->_getHelper()->__('Check No and Date are required fields');
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
if ($errorMsg) {
|
| 252 |
+
Mage::throwException($errorMsg);
|
| 253 |
+
}*/
|
| 254 |
+
return $this;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
/**
|
| 258 |
+
* Get checkout session namespace
|
| 259 |
+
*
|
| 260 |
+
* @return Mage_Checkout_Model_Session
|
| 261 |
+
*/
|
| 262 |
+
public function getCheckout() {
|
| 263 |
+
return Mage::getSingleton('checkout/session');
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* Get current quote
|
| 268 |
+
*
|
| 269 |
+
* @return Mage_Sales_Model_Quote
|
| 270 |
+
*/
|
| 271 |
+
public function getQuote() {
|
| 272 |
+
return $this->getCheckout()->getQuote();
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* Get one page checkout model
|
| 277 |
+
*
|
| 278 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
| 279 |
+
*/
|
| 280 |
+
public function getOnepage() {
|
| 281 |
+
return Mage::getSingleton('checkout/type_onepage');
|
| 282 |
+
}
|
| 283 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Safe.php
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Resource_Safe extends Mage_Core_Model_Resource_Db_Abstract
|
| 27 |
+
{
|
| 28 |
+
protected function _construct()
|
| 29 |
+
{
|
| 30 |
+
$this->_init('moip/safe', 'id');
|
| 31 |
+
}
|
| 32 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Safe/Collection.php
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Resource_Safe_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
| 27 |
+
{
|
| 28 |
+
protected function _construct()
|
| 29 |
+
{
|
| 30 |
+
$this->_init('moip/safe');
|
| 31 |
+
}
|
| 32 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Safe/Collection/Abstract.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Resource_Safe_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract{
|
| 27 |
+
protected function _afterLoad()
|
| 28 |
+
{
|
| 29 |
+
parent::_afterLoad();
|
| 30 |
+
|
| 31 |
+
return $this;
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Transactions.php
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/class Monstroestudio_Moip_Model_Resource_Transactions extends Mage_Core_Model_Resource_Db_Abstract
|
| 26 |
+
{
|
| 27 |
+
protected function _construct()
|
| 28 |
+
{
|
| 29 |
+
$this->_init('moip/transactions', 'id');
|
| 30 |
+
}
|
| 31 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Transactions/Collection.php
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Resource_Transactions_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
| 27 |
+
{
|
| 28 |
+
protected function _construct()
|
| 29 |
+
{
|
| 30 |
+
$this->_init('moip/transactions');
|
| 31 |
+
}
|
| 32 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Resource/Transactions/Collection/Abstract.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Resource_Transactions_Collection_Abstract extends Mage_Core_Model_Resource_Db_Collection_Abstract{
|
| 27 |
+
protected function _afterLoad()
|
| 28 |
+
{
|
| 29 |
+
parent::_afterLoad();
|
| 30 |
+
|
| 31 |
+
return $this;
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Safe.php
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Safe extends Monstroestudio_Moip_Model_Abstract
|
| 27 |
+
{
|
| 28 |
+
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
parent::_construct();
|
| 32 |
+
$this->_init('moip/safe');
|
| 33 |
+
$this->setIdFieldName('id');
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function loadByCustomer($id){
|
| 38 |
+
if($id == null){
|
| 39 |
+
return false;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
$collection = $this->getCollection()->addFilter('customer_id', array('eq' => $id))->load();
|
| 43 |
+
|
| 44 |
+
if(count($collection) > 0){
|
| 45 |
+
return $collection;
|
| 46 |
+
}else{
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
public function loadBySafe($token){
|
| 52 |
+
if($token == null){
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$collection = $this->getCollection()->addFilter('token', array('eq' => $token))->load();
|
| 57 |
+
|
| 58 |
+
if(count($collection) > 0){
|
| 59 |
+
return $collection;
|
| 60 |
+
}else{
|
| 61 |
+
return false;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Source/Ccmaxparcelas.php
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Source_Ccmaxparcelas {
|
| 27 |
+
public function toOptionArray() {
|
| 28 |
+
return array(
|
| 29 |
+
array('value' => 1, 'label' => '1'),
|
| 30 |
+
array('value' => 2, 'label' => '2'),
|
| 31 |
+
array('value' => 3, 'label' => '3'),
|
| 32 |
+
array('value' => 4, 'label' => '4'),
|
| 33 |
+
array('value' => 5, 'label' => '5'),
|
| 34 |
+
array('value' => 6, 'label' => '6'),
|
| 35 |
+
array('value' => 7, 'label' => '7'),
|
| 36 |
+
array('value' => 8, 'label' => '8'),
|
| 37 |
+
array('value' => 9, 'label' => '9'),
|
| 38 |
+
array('value' => 10, 'label' => '10'),
|
| 39 |
+
array('value' => 11, 'label' => '11'),
|
| 40 |
+
array('value' => 12, 'label' => '12')
|
| 41 |
+
|
| 42 |
+
);
|
| 43 |
+
}
|
| 44 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Source/Paymentmethods.php
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Source_Paymentmethods {
|
| 27 |
+
public function toOptionArray() {
|
| 28 |
+
return array(
|
| 29 |
+
array('value' => 'cc', 'label' => 'Cartão de Crédito'),
|
| 30 |
+
array('value' => 'boleto', 'label' => 'Boleto Bancário'),
|
| 31 |
+
array('value' => 'deposito', 'label' => 'Depósito Online')
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Source/Recebimento.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Source_Recebimento {
|
| 27 |
+
public function toOptionArray() {
|
| 28 |
+
return array(
|
| 29 |
+
array('value' => 'Parcelado', 'label' => 'Sim'),
|
| 30 |
+
array('value' => 'AVista', 'label' => 'Não'),
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Source/Tipovencboleto.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Source_Tipovencboleto {
|
| 27 |
+
public function toOptionArray() {
|
| 28 |
+
return array(
|
| 29 |
+
array('value' => true, 'label' => 'Dias úteis'),
|
| 30 |
+
array('value' => false, 'label' => 'Dias corridos'),
|
| 31 |
+
);
|
| 32 |
+
}
|
| 33 |
+
}
|
app/code/local/Monstroestudio/Moip/Model/Transactions.php
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_Model_Transactions extends Monstroestudio_Moip_Model_Abstract
|
| 27 |
+
{
|
| 28 |
+
|
| 29 |
+
protected function _construct()
|
| 30 |
+
{
|
| 31 |
+
parent::_construct();
|
| 32 |
+
$this->_init('moip/transactions');
|
| 33 |
+
$this->setIdFieldName('id');
|
| 34 |
+
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
public function loadByOrder($incrementId){
|
| 38 |
+
if($incrementId == null){
|
| 39 |
+
return false;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
$collection = $this->getCollection()->addFilter('order_id', array('eq' => $incrementId))->load();
|
| 43 |
+
|
| 44 |
+
if(count($collection) > 0){
|
| 45 |
+
return $collection->getFirstItem();
|
| 46 |
+
}else{
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
}
|
app/code/local/Monstroestudio/Moip/controllers/CheckoutController.php
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Monstro Estúdio e Groh & Partners.
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
class Monstroestudio_Moip_CheckoutController extends Mage_Core_Controller_Front_Action
|
| 27 |
+
{
|
| 28 |
+
/**
|
| 29 |
+
* Página de sucesso do módulo
|
| 30 |
+
*/
|
| 31 |
+
public function AuthorizeAction(){
|
| 32 |
+
$this->loadLayout();
|
| 33 |
+
$this->renderLayout();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Get checkout session namespace
|
| 38 |
+
*
|
| 39 |
+
* @return Mage_Checkout_Model_Session
|
| 40 |
+
*/
|
| 41 |
+
protected function getCheckout()
|
| 42 |
+
{
|
| 43 |
+
return Mage::getSingleton('checkout/session');
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* Get current quote
|
| 48 |
+
*
|
| 49 |
+
* @return Mage_Sales_Model_Quote
|
| 50 |
+
*/
|
| 51 |
+
protected function getQuote()
|
| 52 |
+
{
|
| 53 |
+
return $this->getCheckout()->getQuote();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Get one page checkout model
|
| 58 |
+
*
|
| 59 |
+
* @return Mage_Checkout_Model_Type_Onepage
|
| 60 |
+
*/
|
| 61 |
+
protected function getOnepage()
|
| 62 |
+
{
|
| 63 |
+
return Mage::getSingleton('checkout/type_onepage');
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Retorno do MoIP
|
| 68 |
+
*/
|
| 69 |
+
public function updateAction(){
|
| 70 |
+
if($this->getRequest()->isPost()){
|
| 71 |
+
$data = $this->getRequest()->getPost();
|
| 72 |
+
$transaction_id = preg_replace('/[^0-9,.\-_]/', '', $data['id_transacao']);
|
| 73 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($transaction_id);
|
| 74 |
+
$customer = $order->getCustomerId();
|
| 75 |
+
$safeModel = Mage::getModel('moip/safe');
|
| 76 |
+
|
| 77 |
+
if(isset($data['cofre']) && strlen($data['cofre']) > 4){
|
| 78 |
+
if(!$safeModel->loadBySafe($data['cofre']) && (bool)Mage::getModel('moip/transactions')->loadByOrder($transaction_id)->getAcceptSafe()){
|
| 79 |
+
$safeData = array(
|
| 80 |
+
'customer_id' => $customer,
|
| 81 |
+
'token' => $data['cofre'],
|
| 82 |
+
'digits' => $data['cartao_final'],
|
| 83 |
+
'operator' => $data['cartao_bandeira']
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
$safeModel->setData($safeData)->save();
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
$isOrderAlreadyAuthorized = ($order->getStatus() == 'authorized' || $order->getStatus() == 'closed' || $order->getStatus() == 'complete');
|
| 91 |
+
|
| 92 |
+
switch ((int)$data['status_pagamento']){
|
| 93 |
+
case 1:
|
| 94 |
+
if($isOrderAlreadyAuthorized){
|
| 95 |
+
return false;
|
| 96 |
+
}
|
| 97 |
+
$order_status = 'authorized';
|
| 98 |
+
$order_state = Mage_Sales_Model_Order::STATE_PROCESSING;
|
| 99 |
+
break;
|
| 100 |
+
case 2:
|
| 101 |
+
if($isOrderAlreadyAuthorized){
|
| 102 |
+
return false;
|
| 103 |
+
}
|
| 104 |
+
$order_status = 'iniciado';
|
| 105 |
+
$order_state = Mage_Sales_Model_Order::STATE_HOLDED;
|
| 106 |
+
break;
|
| 107 |
+
case 3:
|
| 108 |
+
if($isOrderAlreadyAuthorized){
|
| 109 |
+
return false;
|
| 110 |
+
}
|
| 111 |
+
$order_status = 'boleto_impresso';
|
| 112 |
+
$order_state = Mage_Sales_Model_Order::STATE_HOLDED;
|
| 113 |
+
break;
|
| 114 |
+
case 4:
|
| 115 |
+
$order_status = 'concluido';
|
| 116 |
+
$order_state = Mage_Sales_Model_Order::STATE_PROCESSING;
|
| 117 |
+
break;
|
| 118 |
+
case 5:
|
| 119 |
+
if($isOrderAlreadyAuthorized){
|
| 120 |
+
return false;
|
| 121 |
+
}
|
| 122 |
+
$order_status = 'canceled';
|
| 123 |
+
$order_state = Mage_Sales_Model_Order::STATE_CANCELED;
|
| 124 |
+
break;
|
| 125 |
+
case 6:
|
| 126 |
+
if($isOrderAlreadyAuthorized){
|
| 127 |
+
return false;
|
| 128 |
+
}
|
| 129 |
+
$order_status = 'payment_review';
|
| 130 |
+
$order_state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
|
| 131 |
+
break;
|
| 132 |
+
case 7:
|
| 133 |
+
//reembolso
|
| 134 |
+
$order_status = 'closed';
|
| 135 |
+
$order_state = Mage_Sales_Model_Order::CLOSED;
|
| 136 |
+
return false;
|
| 137 |
+
break;
|
| 138 |
+
case 9:
|
| 139 |
+
//reembolso
|
| 140 |
+
$order_status = 'closed';
|
| 141 |
+
$order_state = Mage_Sales_Model_Order::CLOSED;
|
| 142 |
+
return false;
|
| 143 |
+
break;
|
| 144 |
+
|
| 145 |
+
}
|
| 146 |
+
$comment = '';
|
| 147 |
+
if($order_status !== 'closed'){
|
| 148 |
+
$order->setState($order_state, $order_status, $comment, $notified = true, $includeComment = false)->save();
|
| 149 |
+
if($order_status == 'authorized'){
|
| 150 |
+
$this->generateInvoice($order);
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* generateInvoice function.
|
| 159 |
+
*
|
| 160 |
+
* @access protected
|
| 161 |
+
* @param Mage_Sales_Model_Order $order
|
| 162 |
+
* @return void
|
| 163 |
+
*/
|
| 164 |
+
protected function generateInvoice(Mage_Sales_Model_Order $order){
|
| 165 |
+
$status = $order->getStatus();
|
| 166 |
+
$state = $order->getState();
|
| 167 |
+
if (!$order->canInvoice()) {
|
| 168 |
+
$order->addStatusHistoryComment('Pedido não pode ser faturado.', false);
|
| 169 |
+
$order->save();
|
| 170 |
+
return false;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
| 174 |
+
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
|
| 175 |
+
$invoice->register();
|
| 176 |
+
$invoice->getOrder()->setCustomerNoteNotify(false);
|
| 177 |
+
$invoice->getOrder()->setIsInProcess(true);
|
| 178 |
+
$order->addStatusHistoryComment('Pagamento realizado e autorizado pela solução de pagamentos MOIP.', false);
|
| 179 |
+
$transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
|
| 180 |
+
$transactionSave->save();
|
| 181 |
+
|
| 182 |
+
$order->setState($state, $status, '', $notified = true, $includeComment = false);
|
| 183 |
+
$order->save();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
}
|
app/code/local/Monstroestudio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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Monstroestudio_Moip>
|
| 5 |
+
<version>1.0.0</version>
|
| 6 |
+
</Monstroestudio_Moip>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<models>
|
| 10 |
+
<moip>
|
| 11 |
+
<class>Monstroestudio_Moip_Model</class>
|
| 12 |
+
<resourceModel>moip_resource</resourceModel>
|
| 13 |
+
</moip>
|
| 14 |
+
<moip_resource>
|
| 15 |
+
<class>Monstroestudio_Moip_Model_Resource</class>
|
| 16 |
+
<entities>
|
| 17 |
+
<transactions>
|
| 18 |
+
<table>moip_transactions</table>
|
| 19 |
+
</transactions>
|
| 20 |
+
<safe>
|
| 21 |
+
<table>moip_safe</table>
|
| 22 |
+
</safe>
|
| 23 |
+
</entities>
|
| 24 |
+
</moip_resource>
|
| 25 |
+
</models>
|
| 26 |
+
<helpers>
|
| 27 |
+
<moip>
|
| 28 |
+
<class>Monstroestudio_Moip_Helper</class>
|
| 29 |
+
</moip>
|
| 30 |
+
</helpers>
|
| 31 |
+
<resources>
|
| 32 |
+
<moip_setup>
|
| 33 |
+
<setup>
|
| 34 |
+
<module>Monstroestudio_Moip</module>
|
| 35 |
+
</setup>
|
| 36 |
+
<connection>
|
| 37 |
+
<use>core_setup</use>
|
| 38 |
+
</connection>
|
| 39 |
+
</moip_setup>
|
| 40 |
+
<moip_write>
|
| 41 |
+
<connection>
|
| 42 |
+
<use>core_write</use>
|
| 43 |
+
</connection>
|
| 44 |
+
</moip_write>
|
| 45 |
+
<moip_read>
|
| 46 |
+
<connection>
|
| 47 |
+
<use>core_read</use>
|
| 48 |
+
</connection>
|
| 49 |
+
</moip_read>
|
| 50 |
+
</resources>
|
| 51 |
+
<blocks>
|
| 52 |
+
<moip><class>Monstroestudio_Moip_Block</class></moip>
|
| 53 |
+
</blocks>
|
| 54 |
+
<payment>
|
| 55 |
+
<groups>
|
| 56 |
+
<moip>moip</moip>
|
| 57 |
+
</groups>
|
| 58 |
+
</payment>
|
| 59 |
+
<events>
|
| 60 |
+
<admin_system_config_section_save_after>
|
| 61 |
+
<observers>
|
| 62 |
+
<auto_update_street_lines>
|
| 63 |
+
<class>moip/observer</class>
|
| 64 |
+
<method>updateStreetLines</method>
|
| 65 |
+
</auto_update_street_lines>
|
| 66 |
+
</observers>
|
| 67 |
+
</admin_system_config_section_save_after>
|
| 68 |
+
<moip_sales_quote_assign_data_after>
|
| 69 |
+
<observers>
|
| 70 |
+
<set_custom_discount_moip>
|
| 71 |
+
<type>singleton</type>
|
| 72 |
+
<class>moip/observer</class>
|
| 73 |
+
<method>setDiscount</method>
|
| 74 |
+
</set_custom_discount_moip>
|
| 75 |
+
<set_credit_card_tax_moip>
|
| 76 |
+
<type>singleton</type>
|
| 77 |
+
<class>moip/observer</class>
|
| 78 |
+
<method>setCCTax</method>
|
| 79 |
+
</set_credit_card_tax_moip>
|
| 80 |
+
</observers>
|
| 81 |
+
</moip_sales_quote_assign_data_after>
|
| 82 |
+
</events>
|
| 83 |
+
</global>
|
| 84 |
+
<frontend>
|
| 85 |
+
<routers>
|
| 86 |
+
<moip>
|
| 87 |
+
<use>standard</use>
|
| 88 |
+
<args>
|
| 89 |
+
<module>Monstroestudio_Moip</module>
|
| 90 |
+
<frontName>moip</frontName>
|
| 91 |
+
</args>
|
| 92 |
+
</moip>
|
| 93 |
+
</routers>
|
| 94 |
+
<layout>
|
| 95 |
+
<updates>
|
| 96 |
+
<moip>
|
| 97 |
+
<file>monstroestudio/moip.xml</file>
|
| 98 |
+
</moip>
|
| 99 |
+
</updates>
|
| 100 |
+
</layout>
|
| 101 |
+
</frontend>
|
| 102 |
+
<admin>
|
| 103 |
+
<routers>
|
| 104 |
+
<adminhtml>
|
| 105 |
+
<args>
|
| 106 |
+
<modules>
|
| 107 |
+
<moip after="Mage_Adminhtml">Monstroestudio_Moip</moip>
|
| 108 |
+
</modules>
|
| 109 |
+
</args>
|
| 110 |
+
</adminhtml>
|
| 111 |
+
</routers>
|
| 112 |
+
</admin>
|
| 113 |
+
<adminhtml>
|
| 114 |
+
<translate>
|
| 115 |
+
<modules>
|
| 116 |
+
<Monstroestudio_Moip>
|
| 117 |
+
<files>
|
| 118 |
+
<default>Monstroestudio_Moip.csv</default>
|
| 119 |
+
</files>
|
| 120 |
+
</Monstroestudio_Moip>
|
| 121 |
+
</modules>
|
| 122 |
+
</translate>
|
| 123 |
+
<layout>
|
| 124 |
+
<updates>
|
| 125 |
+
<moip>
|
| 126 |
+
<file>moip.xml</file>
|
| 127 |
+
</moip>
|
| 128 |
+
</updates>
|
| 129 |
+
</layout>
|
| 130 |
+
<acl>
|
| 131 |
+
<resources>
|
| 132 |
+
<admin>
|
| 133 |
+
<children>
|
| 134 |
+
<system>
|
| 135 |
+
<children>
|
| 136 |
+
<config>
|
| 137 |
+
<children>
|
| 138 |
+
<moip translate="title" module="moip">
|
| 139 |
+
<title>Moip Settings</title>
|
| 140 |
+
</moip>
|
| 141 |
+
</children>
|
| 142 |
+
</config>
|
| 143 |
+
</children>
|
| 144 |
+
</system>
|
| 145 |
+
</children>
|
| 146 |
+
</admin>
|
| 147 |
+
</resources>
|
| 148 |
+
</acl>
|
| 149 |
+
</adminhtml>
|
| 150 |
+
<default>
|
| 151 |
+
<payment>
|
| 152 |
+
<moip>
|
| 153 |
+
<active>0</active>
|
| 154 |
+
<payment_action>authorize</payment_action>
|
| 155 |
+
<title>MoIP - Cartão, Boleto e Transferência</title>
|
| 156 |
+
<methods>cc,boleto,deposito</methods>
|
| 157 |
+
<parcelado>1</parcelado>
|
| 158 |
+
<parcelado_avista>1</parcelado_avista>
|
| 159 |
+
<numero_max_parcelas>12</numero_max_parcelas>
|
| 160 |
+
<parcela_min>5</parcela_min>
|
| 161 |
+
<parcelas_s_juros>0</parcelas_s_juros>
|
| 162 |
+
<juros_parcela>1.99</juros_parcela>
|
| 163 |
+
<desconto_boleto>0</desconto_boleto>
|
| 164 |
+
<desconto_transf>0</desconto_transf>
|
| 165 |
+
<vencimento_boleto>5</vencimento_boleto>
|
| 166 |
+
<bloquear_boleto_estoque>0</bloquear_boleto_estoque>
|
| 167 |
+
<sandbox>0</sandbox>
|
| 168 |
+
<order_status>pending</order_status>
|
| 169 |
+
<model>moip/paymentMethod</model>
|
| 170 |
+
</moip>
|
| 171 |
+
</payment>
|
| 172 |
+
<customer>
|
| 173 |
+
<address>
|
| 174 |
+
<street_lines>4</street_lines>
|
| 175 |
+
</address>
|
| 176 |
+
</customer>
|
| 177 |
+
</default>
|
| 178 |
+
</config>
|
app/code/local/Monstroestudio/Moip/etc/system.xml
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<sections>
|
| 4 |
+
<payment>
|
| 5 |
+
<groups>
|
| 6 |
+
<moip translate="label" module="moip">
|
| 7 |
+
<label><![CDATA[MoIP Express - Monstro Estúdio e Groh & Partners Brasil]]></label>
|
| 8 |
+
<comment><![CDATA[<h3>Módulo Gratuito e 100% desenvolvido pela Monstro Estúdio e a Groh & Partners Brasil. Precisa de ajuda com o Módulo ou com quaisquer outros problemas e/ou melhorias na sua loja? Visite, <a href="http://monstroestudio.com.br">monstroestudio.com.br</a> e <a href="http://grohpartners.com">grohpartners.com</a></h3>]]></comment>
|
| 9 |
+
<frontend_type>text</frontend_type>
|
| 10 |
+
<sort_order>01</sort_order>
|
| 11 |
+
<show_in_default>1</show_in_default>
|
| 12 |
+
<show_in_website>1</show_in_website>
|
| 13 |
+
<show_in_store>1</show_in_store>
|
| 14 |
+
<fields>
|
| 15 |
+
<active translate="label">
|
| 16 |
+
<label>Ativo</label>
|
| 17 |
+
<frontend_type>select</frontend_type>
|
| 18 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 19 |
+
<sort_order>10</sort_order>
|
| 20 |
+
<show_in_default>1</show_in_default>
|
| 21 |
+
<show_in_website>1</show_in_website>
|
| 22 |
+
<show_in_store>0</show_in_store>
|
| 23 |
+
</active>
|
| 24 |
+
<title translate="label">
|
| 25 |
+
<label>Título</label>
|
| 26 |
+
<frontend_type>text</frontend_type>
|
| 27 |
+
<sort_order>30</sort_order>
|
| 28 |
+
<show_in_default>1</show_in_default>
|
| 29 |
+
<show_in_website>1</show_in_website>
|
| 30 |
+
<show_in_store>1</show_in_store>
|
| 31 |
+
<tooltip><![CDATA[O nome fantasia usado na cobrança é o mesmo nome da loja Magento, para mudar vá em:<hr style="margin: 5px 0;border:0;border-top:1px solid #ccc;">Sistema(System) > Configurações(Configuration) > Geral(General)<hr style="margin: 5px 0;border:0;border-top:1px solid #ccc;"> Na aba 'Dados da Loja'(Store information) mude o campo 'Nome da Loja'(Store Name) ]]></tooltip>
|
| 32 |
+
<depends><active>1</active></depends>
|
| 33 |
+
</title>
|
| 34 |
+
<login translate="label">
|
| 35 |
+
<label>Login MoIP</label>
|
| 36 |
+
<frontend_type>text</frontend_type>
|
| 37 |
+
<sort_order>40</sort_order>
|
| 38 |
+
<show_in_default>1</show_in_default>
|
| 39 |
+
<show_in_website>1</show_in_website>
|
| 40 |
+
<show_in_store>0</show_in_store>
|
| 41 |
+
<depends><active>1</active></depends>
|
| 42 |
+
</login>
|
| 43 |
+
<methods tranlate="label">
|
| 44 |
+
<label>Métodos de pagamento</label>
|
| 45 |
+
<frontend_type>multiselect</frontend_type>
|
| 46 |
+
<source_model>moip/source_paymentmethods</source_model>
|
| 47 |
+
<sort_order>50</sort_order>
|
| 48 |
+
<show_in_default>1</show_in_default>
|
| 49 |
+
<show_in_website>1</show_in_website>
|
| 50 |
+
<show_in_store>0</show_in_store>
|
| 51 |
+
<depends><active>1</active></depends>
|
| 52 |
+
</methods>
|
| 53 |
+
<parcelado translate="label">
|
| 54 |
+
<label>Ativar Parcelamento</label>
|
| 55 |
+
<frontend_type>select</frontend_type>
|
| 56 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 57 |
+
<sort_order>60</sort_order>
|
| 58 |
+
<show_in_default>1</show_in_default>
|
| 59 |
+
<show_in_website>1</show_in_website>
|
| 60 |
+
<show_in_store>0</show_in_store>
|
| 61 |
+
<depends><methods>cc</methods><active>1</active></depends>
|
| 62 |
+
</parcelado>
|
| 63 |
+
<parcelado_avista translate="label">
|
| 64 |
+
<label>Receber Parcelado A vista?</label>
|
| 65 |
+
<frontend_type>select</frontend_type>
|
| 66 |
+
<source_model>moip/source_recebimento</source_model>
|
| 67 |
+
<sort_order>70</sort_order>
|
| 68 |
+
<show_in_default>1</show_in_default>
|
| 69 |
+
<show_in_website>1</show_in_website>
|
| 70 |
+
<show_in_store>0</show_in_store>
|
| 71 |
+
<comment>Padrão MoIP é receber A vista, contate o MoIP antes de mudar esta opção.</comment>
|
| 72 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 73 |
+
</parcelado_avista>
|
| 74 |
+
<numero_max_parcelas translate="label">
|
| 75 |
+
<label>Número máximo de parcelas</label>
|
| 76 |
+
<frontend_type>select</frontend_type>
|
| 77 |
+
<source_model>moip/source_ccmaxparcelas</source_model>
|
| 78 |
+
<sort_order>70</sort_order>
|
| 79 |
+
<show_in_default>1</show_in_default>
|
| 80 |
+
<show_in_website>1</show_in_website>
|
| 81 |
+
<show_in_store>0</show_in_store>
|
| 82 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 83 |
+
</numero_max_parcelas>
|
| 84 |
+
<parcela_min translate="label">
|
| 85 |
+
<label>Valor mínimo das parcelas</label>
|
| 86 |
+
<frontend_type>text</frontend_type>
|
| 87 |
+
<sort_order>80</sort_order>
|
| 88 |
+
<show_in_default>1</show_in_default>
|
| 89 |
+
<show_in_website>1</show_in_website>
|
| 90 |
+
<show_in_store>0</show_in_store>
|
| 91 |
+
<comment>Valor mínimo é 5.</comment>
|
| 92 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 93 |
+
<validate>validate-number validate-greater-than-zero </validate>
|
| 94 |
+
</parcela_min>
|
| 95 |
+
<parcelas_s_juros translate="label">
|
| 96 |
+
<label>Parcela sem juros</label>
|
| 97 |
+
<frontend_type>text</frontend_type>
|
| 98 |
+
<sort_order>90</sort_order>
|
| 99 |
+
<show_in_default>1</show_in_default>
|
| 100 |
+
<show_in_website>1</show_in_website>
|
| 101 |
+
<show_in_store>0</show_in_store>
|
| 102 |
+
<validate>validate-number validate-zero-or-greater </validate>
|
| 103 |
+
<comment>Número de parcelas sem juroz. Ex: 3</comment>
|
| 104 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 105 |
+
</parcelas_s_juros>
|
| 106 |
+
<juros_parcela translate="label">
|
| 107 |
+
<label>Juros da parcela</label>
|
| 108 |
+
<frontend_type>text</frontend_type>
|
| 109 |
+
<sort_order>100</sort_order>
|
| 110 |
+
<show_in_default>1</show_in_default>
|
| 111 |
+
<show_in_website>1</show_in_website>
|
| 112 |
+
<show_in_store>0</show_in_store>
|
| 113 |
+
<validate>validate-number validate-zero-or-greater </validate>
|
| 114 |
+
<comment>Usar padrão americano '.' no lugar da ','. Ex: 1.99</comment>
|
| 115 |
+
<tooltip>Não é aplicado para as parcelas sem juros. </tooltip>
|
| 116 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 117 |
+
</juros_parcela>
|
| 118 |
+
<desconto_boleto>
|
| 119 |
+
<label>Desconto no boleto</label>
|
| 120 |
+
<frontend_type>text</frontend_type>
|
| 121 |
+
<sort_order>105</sort_order>
|
| 122 |
+
<show_in_default>1</show_in_default>
|
| 123 |
+
<show_in_website>1</show_in_website>
|
| 124 |
+
<show_in_store>0</show_in_store>
|
| 125 |
+
<validate>validate-number validate-zero-or-greater </validate>
|
| 126 |
+
<depends><active>1</active></depends>
|
| 127 |
+
<comment>refere-se a % de desconto. Obs: não utilizar o simbolo de % e utilizar '.' no lugar da ','</comment>
|
| 128 |
+
</desconto_boleto>
|
| 129 |
+
<tipo_vencimento_boleto>
|
| 130 |
+
<label>Tipo de contagem de dias para vencimento do boleto</label>
|
| 131 |
+
<frontend_type>select</frontend_type>
|
| 132 |
+
<source_model>moip/source_tipovencboleto</source_model>
|
| 133 |
+
<sort_order>109</sort_order>
|
| 134 |
+
<show_in_default>1</show_in_default>
|
| 135 |
+
<show_in_website>1</show_in_website>
|
| 136 |
+
<show_in_store>0</show_in_store>
|
| 137 |
+
<depends><active>1</active></depends>
|
| 138 |
+
</tipo_vencimento_boleto>
|
| 139 |
+
<vencimento_boleto>
|
| 140 |
+
<label>Dias para vencimento do boleto</label>
|
| 141 |
+
<frontend_type>text</frontend_type>
|
| 142 |
+
<sort_order>110</sort_order>
|
| 143 |
+
<show_in_default>1</show_in_default>
|
| 144 |
+
<show_in_website>1</show_in_website>
|
| 145 |
+
<show_in_store>0</show_in_store>
|
| 146 |
+
<validate>validate-number validate-zero-or-greater </validate>
|
| 147 |
+
<depends><active>1</active></depends>
|
| 148 |
+
</vencimento_boleto>
|
| 149 |
+
<instrucao_boleto>
|
| 150 |
+
<label>Instrução a ser inserida no boleto</label>
|
| 151 |
+
<frontend_type>textarea</frontend_type>
|
| 152 |
+
<sort_order>115</sort_order>
|
| 153 |
+
<show_in_default>1</show_in_default>
|
| 154 |
+
<show_in_website>1</show_in_website>
|
| 155 |
+
<show_in_store>0</show_in_store>
|
| 156 |
+
<validate></validate>
|
| 157 |
+
<depends><active>1</active></depends>
|
| 158 |
+
<comment><![CDATA[<strong style="color:red;">Não utilizar html!!!</strong>]]></comment>
|
| 159 |
+
</instrucao_boleto>
|
| 160 |
+
|
| 161 |
+
<bloquear_boleto_estoque translate="label">
|
| 162 |
+
<label>Bloquear pagamento com boleto para produtos com baixo estoque?</label>
|
| 163 |
+
<frontend_type>select</frontend_type>
|
| 164 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 165 |
+
<sort_order>120</sort_order>
|
| 166 |
+
<show_in_default>1</show_in_default>
|
| 167 |
+
<show_in_website>1</show_in_website>
|
| 168 |
+
<show_in_store>0</show_in_store>
|
| 169 |
+
<comment>Bloqueia todo o carrinho caso um produto esteja abaixo do estoque mínimo. Mais infomações no tooltip ao lado ------> ?</comment>
|
| 170 |
+
<tooltip><![CDATA[Usamos as configurações de alerta de produto de baixo estoque do Magento, para muda-as vá em:<hr style="margin: 5px 0;border:0;border-top:1px solid #ccc;">Sistema(System) > Configurações(Configuration) > Estoque(Inventory)<hr style="margin: 5px 0;border:0;border-top:1px solid #ccc;">Na aba 'Opções de Estoque'(Stock Options) mude o valor do campo 'Notificar quantidade abaixo de'(Notify for Quantity Below) para o valor desejado.]]></tooltip>
|
| 171 |
+
<depends><methods>cc</methods><parcelado>1</parcelado><active>1</active></depends>
|
| 172 |
+
</bloquear_boleto_estoque>
|
| 173 |
+
<desconto_transf>
|
| 174 |
+
<label>Desconto na transferência bancária</label>
|
| 175 |
+
<frontend_type>text</frontend_type>
|
| 176 |
+
<sort_order>175</sort_order>
|
| 177 |
+
<show_in_default>1</show_in_default>
|
| 178 |
+
<show_in_website>1</show_in_website>
|
| 179 |
+
<show_in_store>0</show_in_store>
|
| 180 |
+
<validate>validate-number validate-zero-or-greater </validate>
|
| 181 |
+
<depends><active>1</active></depends>
|
| 182 |
+
<comment>refere-se a % de desconto. Obs: não utilizar o simbolo de % e utilizar '.' no lugar da ','</comment>
|
| 183 |
+
</desconto_transf>
|
| 184 |
+
<test translate="label">
|
| 185 |
+
<label>Sandbox?</label>
|
| 186 |
+
<frontend_type>select</frontend_type>
|
| 187 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 188 |
+
<sort_order>180</sort_order>
|
| 189 |
+
<show_in_default>1</show_in_default>
|
| 190 |
+
<show_in_website>1</show_in_website>
|
| 191 |
+
<show_in_store>0</show_in_store>
|
| 192 |
+
<comment>Usar somente caso a conta seja Sandbox.</comment>
|
| 193 |
+
<tooltip>Os pagamentos feitos em Sandbox não tem valor monetário real e são destinados somente para testes.</tooltip>
|
| 194 |
+
<depends><active>1</active></depends>
|
| 195 |
+
</test>
|
| 196 |
+
</fields>
|
| 197 |
+
</moip>
|
| 198 |
+
</groups>
|
| 199 |
+
</payment>
|
| 200 |
+
</sections>
|
| 201 |
+
</config>
|
app/code/local/Monstroestudio/Moip/sql/moip_setup/mysql4-install-1.0.0.php
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
*
|
| 7 |
+
* This source file is subject to the EULA
|
| 8 |
+
* It is also available through the world-wide-web at this URL:
|
| 9 |
+
* http://www.gnu.org/copyleft/gpl.html
|
| 10 |
+
*
|
| 11 |
+
* =================================================================
|
| 12 |
+
* MAGENTO EDITION USAGE NOTICE
|
| 13 |
+
* =================================================================
|
| 14 |
+
* This package designed for Magento COMMUNITY edition
|
| 15 |
+
* Monstro Estúdio e Groh & Partners does not guarantee correct work of this extension
|
| 16 |
+
* on any other Magento edition except Magento COMMUNITY edition.
|
| 17 |
+
* Monstro Estúdio e Groh & Partners does not provide extension support in case of
|
| 18 |
+
* incorrect edition usage.
|
| 19 |
+
* =================================================================
|
| 20 |
+
*
|
| 21 |
+
* @category Monstroestudio
|
| 22 |
+
* @package Monstroestudio_Moip
|
| 23 |
+
* @copyright Copyright (c) 2010-2014 Monstro Estúdio e Groh & Partners Brasil Co. (http://www.aheadworks.com)
|
| 24 |
+
* @license http://www.gnu.org/copyleft/gpl.html
|
| 25 |
+
*/
|
| 26 |
+
$installer = $this;
|
| 27 |
+
$installer->startSetup();
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
// insert the product attribute to ignore boleto for some products
|
| 31 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 32 |
+
|
| 33 |
+
$config = array(
|
| 34 |
+
'position' => 1,
|
| 35 |
+
'required'=> 0,
|
| 36 |
+
'label' => 'Proibir Compra Por Boleto:',
|
| 37 |
+
'type' => 'int',
|
| 38 |
+
'input'=>'boolean',
|
| 39 |
+
'apply_to'=>'simple,bundle,grouped,configurable',
|
| 40 |
+
'note'=>'Proibe a compra do carrinho com boleto caso o produto esteja no carrinho'
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
$setup->addAttribute('catalog_product', 'proibir_boleto' , $config);
|
| 44 |
+
|
| 45 |
+
//insert new order status
|
| 46 |
+
$statusTable = $installer->getTable('sales/order_status');
|
| 47 |
+
$statusStateTable = $installer->getTable('sales/order_status_state');
|
| 48 |
+
$statusLabelTable = $installer->getTable('sales/order_status_label');
|
| 49 |
+
|
| 50 |
+
$statuses = array();
|
| 51 |
+
$states = array();
|
| 52 |
+
$existingStatus = array();
|
| 53 |
+
|
| 54 |
+
foreach (Mage::getModel('sales/order_status')->getResourceCollection() as $status) {
|
| 55 |
+
$existingStatus[] = $status->getStatus();
|
| 56 |
+
}
|
| 57 |
+
if (!in_array('authorized', $existingStatus)) $statuses[] = array('status' => 'authorized', 'label' => 'Autorizado');
|
| 58 |
+
if (!in_array('iniciado', $existingStatus)) $statuses[] = array('status' => 'iniciado', 'label' => 'Iniciado');
|
| 59 |
+
if (!in_array('boleto_impresso', $existingStatus)) $statuses[] = array('status' => 'boleto_impresso', 'label' => 'Boleto Impresso');
|
| 60 |
+
if (!in_array('concluido', $existingStatus)) $statuses[] = array('status' => 'concluido', 'label' => 'Concluido');
|
| 61 |
+
|
| 62 |
+
if (!in_array('authorized', $existingStatus)) $states[] = array('status' => 'authorized', 'state' => 'processing', 'is_default' => 1);
|
| 63 |
+
if (!in_array('iniciado', $existingStatus)) $states[] = array('status' => 'boleto_impresso', 'state' => 'holded', 'is_default' => 1);
|
| 64 |
+
if (!in_array('boleto_impresso', $existingStatus)) $states[] = array('status' => 'iniciado', 'state' => 'processing', 'is_default' => 1);
|
| 65 |
+
if (!in_array('concluido', $existingStatus)) $states[] = array('status' => 'concluido', 'state' => 'processing', 'is_default' => 1);
|
| 66 |
+
|
| 67 |
+
if(count($statuses)>0){
|
| 68 |
+
$installer->getConnection()->insertArray($statusTable, array('status', 'label'), $statuses);
|
| 69 |
+
$installer->getConnection()->insertArray($statusStateTable, array('status', 'state', 'is_default'), $states);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
// create moip tables
|
| 75 |
+
$installer->run("DROP TABLE IF EXISTS {$this->getTable('moip/transactions')};");
|
| 76 |
+
$installer->run("DROP TABLE IF EXISTS {$this->getTable('moip/safe')};");
|
| 77 |
+
|
| 78 |
+
//Moip Transactions
|
| 79 |
+
$table = $installer->getConnection()
|
| 80 |
+
->newTable($installer->getTable('moip/transactions'))
|
| 81 |
+
|
| 82 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true,'unsigned' => true,'nullable' => false,'primary' => true), 'Id')
|
| 83 |
+
->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Order Id')
|
| 84 |
+
->addColumn('token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Token')
|
| 85 |
+
->addColumn('accept_safe', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Accept Safe')
|
| 86 |
+
->addColumn('data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(), 'Data')
|
| 87 |
+
|
| 88 |
+
->addIndex($installer->getIdxName('moip/transactions', array('order_id')), array('order_id'))
|
| 89 |
+
|
| 90 |
+
->setComment('Moip Transactions');
|
| 91 |
+
$installer->getConnection()->createTable($table);
|
| 92 |
+
// Moip Safe
|
| 93 |
+
$table = $installer->getConnection()
|
| 94 |
+
->newTable($installer->getTable('moip/safe'))
|
| 95 |
+
|
| 96 |
+
->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array('identity' => true,'unsigned' => true,'nullable' => false,'primary' => true), 'Id')
|
| 97 |
+
->addColumn('customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Customer Id')
|
| 98 |
+
->addColumn('digits', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Digits')
|
| 99 |
+
->addColumn('operator', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Operator')
|
| 100 |
+
->addColumn('token', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(), 'Token')
|
| 101 |
+
|
| 102 |
+
->addIndex($installer->getIdxName('moip/safe', array('customer_id', 'token')), array('customer_id', 'token'))
|
| 103 |
+
|
| 104 |
+
->setComment('Moip Safe');
|
| 105 |
+
$installer->getConnection()->createTable($table);
|
| 106 |
+
|
| 107 |
+
$installer->endSetup();
|
| 108 |
+
|
| 109 |
+
$directory_country_region = Mage::getSingleton('core/resource')->getTableName('directory_country_region');
|
| 110 |
+
$directory_country_region_name = Mage::getSingleton('core/resource')->getTableName('directory_country_region_name');
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
$installer->run("
|
| 114 |
+
DELETE from `".$directory_country_region."` WHERE `country_id`='BR';
|
| 115 |
+
DELETE from `".$directory_country_region_name."` WHERE `country_id`='BR';
|
| 116 |
+
|
| 117 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 118 |
+
('BR', 'AC', 'Acre');
|
| 119 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 120 |
+
('en_US', LAST_INSERT_ID(), 'Acre'), ('pt_BR', LAST_INSERT_ID(), 'Acre');
|
| 121 |
+
|
| 122 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 123 |
+
('BR', 'AL', 'Alagoas');
|
| 124 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 125 |
+
('en_US', LAST_INSERT_ID(), 'Alagoas'), ('pt_BR', LAST_INSERT_ID(), 'Alagoas');
|
| 126 |
+
|
| 127 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 128 |
+
('BR', 'AP', 'Amapá');
|
| 129 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 130 |
+
('en_US', LAST_INSERT_ID(), 'Amapá'), ('pt_BR', LAST_INSERT_ID(), 'Amapá');
|
| 131 |
+
|
| 132 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 133 |
+
('BR', 'AM', 'Amazonas');
|
| 134 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 135 |
+
('en_US', LAST_INSERT_ID(), 'Amazonas'), ('pt_BR', LAST_INSERT_ID(), 'Amazonas');
|
| 136 |
+
|
| 137 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 138 |
+
('BR', 'BA', 'Bahia');
|
| 139 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 140 |
+
('en_US', LAST_INSERT_ID(), 'Bahia'), ('pt_BR', LAST_INSERT_ID(), 'Bahia');
|
| 141 |
+
|
| 142 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 143 |
+
('BR', 'CE', 'Ceará');
|
| 144 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 145 |
+
('en_US', LAST_INSERT_ID(), 'Ceará'), ('pt_BR', LAST_INSERT_ID(), 'Ceará');
|
| 146 |
+
|
| 147 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 148 |
+
('BR', 'DF', 'Distrito Federal');
|
| 149 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 150 |
+
('en_US', LAST_INSERT_ID(), 'Distrito Federal'), ('pt_BR', LAST_INSERT_ID(), 'Distrito Federal');
|
| 151 |
+
|
| 152 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 153 |
+
('BR', 'ES', 'Espírito Santo');
|
| 154 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 155 |
+
('en_US', LAST_INSERT_ID(), 'Espírito Santo'), ('pt_BR', LAST_INSERT_ID(), 'Espírito Santo');
|
| 156 |
+
|
| 157 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 158 |
+
('BR', 'GO', 'Goiás');
|
| 159 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 160 |
+
('en_US', LAST_INSERT_ID(), 'Goiás'), ('pt_BR', LAST_INSERT_ID(), 'Goiás');
|
| 161 |
+
|
| 162 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 163 |
+
('BR', 'MA', 'Maranhão');
|
| 164 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 165 |
+
('en_US', LAST_INSERT_ID(), 'Maranhão'), ('pt_BR', LAST_INSERT_ID(), 'Maranhão');
|
| 166 |
+
|
| 167 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 168 |
+
('BR', 'MT', 'Mato Grosso');
|
| 169 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 170 |
+
('en_US', LAST_INSERT_ID(), 'Mato Grosso'), ('pt_BR', LAST_INSERT_ID(), 'Mato Grosso');
|
| 171 |
+
|
| 172 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 173 |
+
('BR', 'MS', 'Mato Grosso do Sul');
|
| 174 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 175 |
+
('en_US', LAST_INSERT_ID(), 'Mato Grosso do Sul'), ('pt_BR', LAST_INSERT_ID(), 'Mato Grosso do Sul');
|
| 176 |
+
|
| 177 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 178 |
+
('BR', 'MG', 'Minas Gerais');
|
| 179 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 180 |
+
('en_US', LAST_INSERT_ID(), 'Minas Gerais'), ('pt_BR', LAST_INSERT_ID(), 'Minas Gerais');
|
| 181 |
+
|
| 182 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 183 |
+
('BR', 'PA', 'Pará');
|
| 184 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 185 |
+
('en_US', LAST_INSERT_ID(), 'Pará'), ('pt_BR', LAST_INSERT_ID(), 'Pará');
|
| 186 |
+
|
| 187 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 188 |
+
('BR', 'PB', 'Paraíba');
|
| 189 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 190 |
+
('en_US', LAST_INSERT_ID(), 'Paraíba'), ('pt_BR', LAST_INSERT_ID(), 'Paraíba');
|
| 191 |
+
|
| 192 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 193 |
+
('BR', 'PR', 'Paraná');
|
| 194 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 195 |
+
('en_US', LAST_INSERT_ID(), 'Paraná'), ('pt_BR', LAST_INSERT_ID(), 'Paraná');
|
| 196 |
+
|
| 197 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 198 |
+
('BR', 'PE', 'Pernambuco');
|
| 199 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 200 |
+
('en_US', LAST_INSERT_ID(), 'Pernambuco'), ('pt_BR', LAST_INSERT_ID(), 'Pernambuco');
|
| 201 |
+
|
| 202 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 203 |
+
('BR', 'PI', 'Piauí');
|
| 204 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 205 |
+
('en_US', LAST_INSERT_ID(), 'Piauí'), ('pt_BR', LAST_INSERT_ID(), 'Piauí');
|
| 206 |
+
|
| 207 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 208 |
+
('BR', 'RJ', 'Rio de Janeiro');
|
| 209 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 210 |
+
('en_US', LAST_INSERT_ID(), 'Rio de Janeiro'), ('pt_BR', LAST_INSERT_ID(), 'Rio de Janeiro');
|
| 211 |
+
|
| 212 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 213 |
+
('BR', 'RN', 'Rio Grande do Norte');
|
| 214 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 215 |
+
('en_US', LAST_INSERT_ID(), 'Rio Grande do Norte'), ('pt_BR', LAST_INSERT_ID(), 'Rio Grande do Norte');
|
| 216 |
+
|
| 217 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 218 |
+
('BR', 'RS', 'Rio Grande do Sul');
|
| 219 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 220 |
+
('en_US', LAST_INSERT_ID(), 'Rio Grande do Sul'), ('pt_BR', LAST_INSERT_ID(), 'Rio Grande do Sul');
|
| 221 |
+
|
| 222 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 223 |
+
('BR', 'RO', 'Rondônia');
|
| 224 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 225 |
+
('en_US', LAST_INSERT_ID(), 'Rondônia'), ('pt_BR', LAST_INSERT_ID(), 'Rondônia');
|
| 226 |
+
|
| 227 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 228 |
+
('BR', 'RR', 'Roraima');
|
| 229 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 230 |
+
('en_US', LAST_INSERT_ID(), 'Roraima'), ('pt_BR', LAST_INSERT_ID(), 'Roraima');
|
| 231 |
+
|
| 232 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 233 |
+
('BR', 'SC', 'Santa Catarina');
|
| 234 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 235 |
+
('en_US', LAST_INSERT_ID(), 'Santa Catarina'), ('pt_BR', LAST_INSERT_ID(), 'Santa Catarina');
|
| 236 |
+
|
| 237 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 238 |
+
('BR', 'SP', 'São Paulo');
|
| 239 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 240 |
+
('en_US', LAST_INSERT_ID(), 'São Paulo'), ('pt_BR', LAST_INSERT_ID(), 'São Paulo');
|
| 241 |
+
|
| 242 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 243 |
+
('BR', 'SE', 'Sergipe');
|
| 244 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 245 |
+
('en_US', LAST_INSERT_ID(), 'Sergipe'), ('pt_BR', LAST_INSERT_ID(), 'Sergipe');
|
| 246 |
+
|
| 247 |
+
INSERT INTO `".$directory_country_region."` (`country_id`, `code`, `default_name`) VALUES
|
| 248 |
+
('BR', 'TO', 'Tocantins');
|
| 249 |
+
INSERT INTO `".$directory_country_region_name."` (`locale`, `region_id`, `name`) VALUES
|
| 250 |
+
('en_US', LAST_INSERT_ID(), 'Tocantins'), ('pt_BR', LAST_INSERT_ID(), 'Tocantins');
|
| 251 |
+
|
| 252 |
+
");
|
app/design/frontend/default/default/layout/monstroestudio/moip.xml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<layout version="0.1.0">
|
| 3 |
+
<checkout_onepage_index>
|
| 4 |
+
<reference name="head">
|
| 5 |
+
<action method="addCss"><stylesheet>monstroestudio/moip/css/styles.css</stylesheet></action>
|
| 6 |
+
<action method="addItem"><type>skin_js</type><name>monstroestudio/moip/js/creditcard.min.js</name></action>
|
| 7 |
+
<action method="addItem"><type>skin_js</type><name>monstroestudio/moip/js/prototype.maskedinput.js</name></action>
|
| 8 |
+
<action method="addItem"><type>skin_js</type><name>monstroestudio/moip/js/validations.js</name></action>
|
| 9 |
+
<action method="addItem"><type>skin_js</type><name>monstroestudio/moip/js/moip-form.js</name></action>
|
| 10 |
+
</reference>
|
| 11 |
+
</checkout_onepage_index>
|
| 12 |
+
<moip_checkout_authorize>
|
| 13 |
+
<reference name="head">
|
| 14 |
+
<action method="addCss"><stylesheet>monstroestudio/moip/css/styles.css</stylesheet></action>
|
| 15 |
+
<action method="addJs"><script>prototype/window.js</script></action>
|
| 16 |
+
<action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
|
| 17 |
+
</reference>
|
| 18 |
+
<reference name="root">
|
| 19 |
+
<action method="setTemplate"><template>page/1column.phtml</template></action>
|
| 20 |
+
</reference>
|
| 21 |
+
<reference name="content">
|
| 22 |
+
<block type="moip/redirect" name="moipRedirect" as="moipRedirect" template="monstroestudio/moip/redirect.phtml" before="-">
|
| 23 |
+
<block type="sales/order_view" name="sales.order.view">
|
| 24 |
+
<block type="sales/order_items" name="order_items" template="sales/order/items.phtml">
|
| 25 |
+
<action method="addItemRender"><type>default</type><block>sales/order_item_renderer_default</block><template>sales/order/items/renderer/default.phtml</template></action>
|
| 26 |
+
<action method="addItemRender"><type>grouped</type><block>sales/order_item_renderer_grouped</block><template>sales/order/items/renderer/default.phtml</template></action>
|
| 27 |
+
<block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">
|
| 28 |
+
<action method="setLabelProperties"><value>colspan="4" class="a-right"</value></action>
|
| 29 |
+
<action method="setValueProperties"><value>class="last a-right"</value></action>
|
| 30 |
+
<block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml" />
|
| 31 |
+
</block>
|
| 32 |
+
</block>
|
| 33 |
+
</block>
|
| 34 |
+
</block>
|
| 35 |
+
</reference>
|
| 36 |
+
</moip_checkout_authorize>
|
| 37 |
+
</layout>
|
app/design/frontend/default/default/template/monstroestudio/moip/form.phtml
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php $_code = $this->getMethodCode();?>
|
| 2 |
+
<div class="moip-paygate" id="payment_form_moip">
|
| 3 |
+
<?php if(!$this->isBoletoValidated() && $this->isBoletoAvailable()): ?>
|
| 4 |
+
<ul class="messages"><li class="notice-msg"><ul><li><span>O pagamento por boleto esta bloqueado porque um dos produtos em seu carrinho tem estoque a baixo de <?php echo Mage::getStoreConfig('cataloginventory/item_options/notify_stock_qty') ?>.</span></li></ul></li></ul>
|
| 5 |
+
<?php endif; ?>
|
| 6 |
+
<?php echo $this->getScripts(); ?>
|
| 7 |
+
<div class="col-left">
|
| 8 |
+
<?php if($this->isCCAvailable()): ?>
|
| 9 |
+
<span data-target="cc" class="active"><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/cc.png')?>" alt="Cartã de Crédito" /><span>Cartão de Crédito</span></span>
|
| 10 |
+
<?php endif; ?>
|
| 11 |
+
<?php if($this->isBoletoAvailable() && $this->isBoletoValidated()): ?>
|
| 12 |
+
<span data-target="boleto"><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/boleto.png')?>" alt="Boleto Bancário" /><span>Boleto Bancário</span></span>
|
| 13 |
+
<?php endif; ?>
|
| 14 |
+
<?php if($this->isTransferenciaAvailable()): ?>
|
| 15 |
+
<span data-target="transferencia"><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/transf.png')?>" alt="Transferência Bancária" /><span>Transferência Bancária</span></span>
|
| 16 |
+
<?php endif; ?>
|
| 17 |
+
<input type="hidden" name="payment[moip_method]" value="cc" id="<?php echo $_code ?>_moip_method"/>
|
| 18 |
+
</div>
|
| 19 |
+
<div class="col-right">
|
| 20 |
+
<div class="safe-seal"></div>
|
| 21 |
+
<?php if($this->isCCAvailable()): ?>
|
| 22 |
+
<div data-name="cc" class="moip-payment-method active">
|
| 23 |
+
<?php if($this->getMoipSafe()): ?>
|
| 24 |
+
<ul class="form-list" id="moip-safe-form">
|
| 25 |
+
<li class="wide">
|
| 26 |
+
<label for="payment[moip_safe]" class="required"><em>*</em>Selecione um cartão ou insira um novo<i></i></label>
|
| 27 |
+
<select name="payment[moip_safe]" id="moip-safe" class="moip_safe">
|
| 28 |
+
<?php echo $this->getMoipSafe(); ?>
|
| 29 |
+
</select>
|
| 30 |
+
<input type="hidden" name="bandeira" value="" id="bandeira-safe" />
|
| 31 |
+
</li>
|
| 32 |
+
<li class="wide cvc" id="moip-safe-cvv-parent">
|
| 33 |
+
<label for="payment[safe_cvv]" class="required"><em>*</em>Código de Segurança<i></i></label>
|
| 34 |
+
<div class="input-box">
|
| 35 |
+
<input type="text" name="payment[safe_cvv]" class="required required-entry input-text" id="<?php echo $_code ?>_safe_cvv" onchange="validateCVV(this);" maxlength="4"/>
|
| 36 |
+
</div>
|
| 37 |
+
<div class="moip-tooltip">
|
| 38 |
+
?
|
| 39 |
+
<div class="tip">
|
| 40 |
+
Olhar no verso do cartão
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
</li>
|
| 44 |
+
<li class="wide parcelas" id="moip-safe-parcelas-parent">
|
| 45 |
+
<label for="payment[safe_parcelas]" class="required"><em>*</em>Parcelas<i></i></label>
|
| 46 |
+
<div class="input-box">
|
| 47 |
+
<select name="payment[safe_parcelas]" class="required required-entry input-text" id="<?php echo $_code ?>_safe_parcelas">
|
| 48 |
+
<?php echo $this->getParcelamento(); ?>
|
| 49 |
+
</select>
|
| 50 |
+
</div>
|
| 51 |
+
<small><?php echo $this->getParcelasTexto() ?></small>
|
| 52 |
+
</li>
|
| 53 |
+
</ul>
|
| 54 |
+
<?php endif; ?>
|
| 55 |
+
<ul class="form-list"<?php if($this->getMoipSafe()): ?>style="display:none"<?php endif; ?> id="moip-new-cc-form">
|
| 56 |
+
<li class="wide cc">
|
| 57 |
+
<label for="payment[cc_number]" class="required"><em>*</em>Número do Cartão</label>
|
| 58 |
+
<div class="input-box">
|
| 59 |
+
<input type="text" placeholder="____ ____ ____ ____" name="payment[cc_number]" class="required input-text required-entry validate-cc-br" id="<?php echo $_code ?>_cc_number" maxlength="19" onblur="selectCCType(this);"/>
|
| 60 |
+
</div>
|
| 61 |
+
</li>
|
| 62 |
+
<li class="wide bandeira">
|
| 63 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="" value="visa" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/visa.png')?>" alt="Visa" /></label>
|
| 64 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="" value="master" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/master.png')?>" alt="Mastecard" /></label>
|
| 65 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="" value="amex" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/amex.png')?>" alt="AmericanExpress" /></label>
|
| 66 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="" value="diners" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/diners.png')?>" alt="DinersClub" /></label>
|
| 67 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="" value="hiper" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/hiper.png')?>" alt="Hipercard" /></label>
|
| 68 |
+
</li>
|
| 69 |
+
<li class="wide validade">
|
| 70 |
+
<label for="payment[validade]" class="required"><em>*</em>Validade</label>
|
| 71 |
+
<div class="input-box">
|
| 72 |
+
<input type="text" name="payment[validade]" id="<?php echo $_code ?>_validade" class="required input-text required-entry validar_vencimento" placeholder="__/__" maxlength="5"/>
|
| 73 |
+
</div>
|
| 74 |
+
</li>
|
| 75 |
+
<li class="wide nome">
|
| 76 |
+
<label for="payment[creditcard_holder_name]" class="required"><em>*</em>Nome impresso no cartão</label>
|
| 77 |
+
<div class="input-box">
|
| 78 |
+
<input type="text" name="payment[creditcard_holder_name]" class="required required-entry input-text" id="<?php echo $_code ?>_creditcard_holder_name" />
|
| 79 |
+
</div>
|
| 80 |
+
</li>
|
| 81 |
+
<li class="wide cvc">
|
| 82 |
+
<label for="payment[cvv]" class="required"><em>*</em>Código de Segurança<i></i></label>
|
| 83 |
+
<div class="input-box">
|
| 84 |
+
<input type="text" name="payment[cvv]" class="required required-entry input-text validar_cvv" id="<?php echo $_code ?>_cvv" onchange="validateCVV(this);" maxlength="4"/>
|
| 85 |
+
</div>
|
| 86 |
+
<div class="moip-tooltip">
|
| 87 |
+
?
|
| 88 |
+
<div class="tip">
|
| 89 |
+
Olhar no verso do cartão
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
</li>
|
| 93 |
+
<li class="wide parcelas">
|
| 94 |
+
<label for="payment[parcelas]" class="required"><em>*</em>Parcelas<i></i></label>
|
| 95 |
+
<div class="input-box">
|
| 96 |
+
<select name="payment[parcelas]" class="required required-entry input-text" id="<?php echo $_code ?>_parcelas">
|
| 97 |
+
<?php echo $this->getParcelamento(); ?>
|
| 98 |
+
</select>
|
| 99 |
+
</div>
|
| 100 |
+
<small><?php echo $this->getParcelasTexto() ?></small>
|
| 101 |
+
</li>
|
| 102 |
+
<li class="wide hide" style="display:none">
|
| 103 |
+
<h4>Dados do Portador do cartão</h4>
|
| 104 |
+
</li>
|
| 105 |
+
<li class="wide hide" style="display:none">
|
| 106 |
+
<label for="payment[cc_holder_cpf]" class="required"><em>*</em>CPF<i></i></label>
|
| 107 |
+
<div class="input-box">
|
| 108 |
+
<input type="text" name="payment[cc_holder_cpf]" class="required required-entry input-text validar_cpf" id="<?php echo $_code ?>_cc_holder_cpf" maxlength="14"/>
|
| 109 |
+
</div>
|
| 110 |
+
</li>
|
| 111 |
+
<li class="wide hide" style="display:none">
|
| 112 |
+
<label for="payment[cc_holder_dob]" class="required"><em>*</em>Data de Nacimento<i></i></label>
|
| 113 |
+
<div class="input-box">
|
| 114 |
+
<input type="text" name="payment[cc_holder_dob]" class="required required-entry input-text validar_dob" id="<?php echo $_code ?>_cc_holder_dob" maxlength="10"/>
|
| 115 |
+
</div>
|
| 116 |
+
</li>
|
| 117 |
+
<li class="wide hide" style="display:none">
|
| 118 |
+
<label for="payment[cc_holder_phone]" class="required"><em>*</em>Telefone<i></i></label>
|
| 119 |
+
<div class="input-box">
|
| 120 |
+
<input type="text" name="payment[cc_holder_phone]" class="required required-entry input-text" id="<?php echo $_code ?>_cc_holder_phone" maxlength="15"/>
|
| 121 |
+
</div>
|
| 122 |
+
</li>
|
| 123 |
+
<li class="wide">
|
| 124 |
+
<label for="payment[cc_save]">Salvar cartão<i></i></label>
|
| 125 |
+
<input type="checkbox" name="payment[cc_save]" class="input-checkbox" id="<?php echo $_code ?>_cc_save" value="1"/>
|
| 126 |
+
</li>
|
| 127 |
+
</ul>
|
| 128 |
+
</div>
|
| 129 |
+
<?php endif; ?>
|
| 130 |
+
<?php if($this->isBoletoAvailable() && $this->isBoletoValidated()): ?>
|
| 131 |
+
<div data-name="boleto" class="moip-payment-method" style="display:none">
|
| 132 |
+
<div>
|
| 133 |
+
<img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/bradesco-boleto.jpg');?>" alt="" class="method-logo"/>
|
| 134 |
+
<div>
|
| 135 |
+
<h4>Pagamento por boleto bancário - Bradesco</h4>
|
| 136 |
+
<?php echo $this->getTextoDescontoBoleto(); ?>
|
| 137 |
+
<p>Pagável em qualquer banco, casas lotéricas ou via internet bank. até o seu vencimento</p>
|
| 138 |
+
</div>
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
<?php endif; ?>
|
| 142 |
+
<?php if($this->isTransferenciaAvailable()): ?>
|
| 143 |
+
<div data-name="transferencia" class="moip-payment-method" style="display:none">
|
| 144 |
+
<div>
|
| 145 |
+
<h4>Transferencia online</h4>
|
| 146 |
+
<ul class="form-list">
|
| 147 |
+
<li class="wide bandeira">
|
| 148 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="required1" value="BancoDoBrasil" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/bb.png');?>" alt="" /></label>
|
| 149 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="required1" value="Bradesco" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/bradesco.png');?>" alt="" /></label>
|
| 150 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="required1" value="Itau" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/itau.png');?>" alt="" /></label>
|
| 151 |
+
<label for="payment[bandeira]" class="bandeira"><input type="radio" name="payment[bandeira]" class="required1" value="Banrisul" /><img src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/banrisul.png');?>" alt="" /></label>
|
| 152 |
+
</li>
|
| 153 |
+
</ul>
|
| 154 |
+
<?php echo $this->getTextoDescontoTransferencia(); ?>
|
| 155 |
+
<p>Após finalizar o pedido você será redirecionado ao site do banco selecionado</p>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
<?php endif; ?>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
app/design/frontend/default/default/template/monstroestudio/moip/redirect.phtml
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div class="row">
|
| 2 |
+
<div class="col50">
|
| 3 |
+
<h1>Compra #<?php echo $this->getOrderId() ?> Realizada com sucesso</h1>
|
| 4 |
+
<div id="retorno-moip" style="dislay:none;">
|
| 5 |
+
<h4>Status do pagamento: <span id="statusPagamento"></span></h3>
|
| 6 |
+
<h4 id="codigoMoip">Código MoIP: <span id="codigoMoipValue"></span></h3>
|
| 7 |
+
<h4 id="bandeiraMoip" style="display:none;">Bandeira: <span id="bandeiraMoipValue"></span></h3>
|
| 8 |
+
<h4 id="parcelasMoip" style="display:none;">Parcelas: <span id="parcelasMoipValue"></span></h3>
|
| 9 |
+
<h4 id="error-moip" style="display:none">Menssagem de erro: <span id="errorMessage"></span></h4>
|
| 10 |
+
</div>
|
| 11 |
+
</div>
|
| 12 |
+
<div class="col50">
|
| 13 |
+
<div id="shipping">
|
| 14 |
+
<h4>Frete:</h4>
|
| 15 |
+
<p><?php echo $this->getShippingDescription(); ?></p>
|
| 16 |
+
</div>
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
<div class="row">
|
| 20 |
+
<div class="col50">
|
| 21 |
+
<h4 class="payment-method-name">Forma de pagamento: <strong><span id="moip-method"></span></strong></h4>
|
| 22 |
+
<?php if($this->getPaymentMethod() == 'boleto'): ?>
|
| 23 |
+
<div class="row">
|
| 24 |
+
<img class="payment-method-img" src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/printer.png') ?>" alt="" /><button id="pagarBoleto" class="moip-payment-button" onclick="boleto();">Imprimir Boleto</button>
|
| 25 |
+
</div>
|
| 26 |
+
<div class="row">
|
| 27 |
+
<div class="moip-alert">Pagavél em qualquer banco, casa lotérica ou via internet bank, até seu vencimento.</div>
|
| 28 |
+
<div class="moip-alert">O boleto estará disponivél, apenas, através do site ou por email</div>
|
| 29 |
+
</div>
|
| 30 |
+
<script type="text/javascript">
|
| 31 |
+
function boleto(){
|
| 32 |
+
var modal = new Window({ className:'moip-modal',title: "Imprima o seu boleto", zIndex:3000,url: $('moip-url').innerHTML,destroyOnClose: true, recenterAuto:false, resizable: false, width:700, height:473, minimizable: false, maximizable: false, draggable: false});
|
| 33 |
+
modal.showCenter(true);
|
| 34 |
+
}
|
| 35 |
+
</script>
|
| 36 |
+
<?php endif; ?>
|
| 37 |
+
<?php if($this->getPaymentMethod() == 'transferencia'): ?>
|
| 38 |
+
<div class="row">
|
| 39 |
+
<img class="payment-method-img" src="<?php echo $this->getSkinUrl('monstroestudio/moip/images/transferencia-icon.png') ?>" alt="" /><a id="pagarTransferencia" class="moip-payment-button" href="" target="_blank">Ir ao site do meu banco</a>
|
| 40 |
+
</div>
|
| 41 |
+
<div class="row">
|
| 42 |
+
<div class="moip-alert">Clique no Botão acima para efetuar o pagamento diretamente no site do seu banco</div>
|
| 43 |
+
</div>
|
| 44 |
+
<?php endif; ?>
|
| 45 |
+
</div>
|
| 46 |
+
<div class="col50">
|
| 47 |
+
<div id="items">
|
| 48 |
+
<?php echo $this->getChildHtml('sales.order.view'); ?>
|
| 49 |
+
<p>Caso exista um item de nome "Taxas" ele se refere ao juros do parcelamento do cartão de crédito.</p>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
<div id="moip-url" style="display:none;"></div>
|
| 55 |
+
<div id="MoipWidget" data-token="<?php echo $this->getToken() ?>" callback-method-success="FUNCAO_DE_SUCESSO" callback-method-error="FUNCAO_DE_FALHA"></div>
|
| 56 |
+
|
| 57 |
+
<script type="text/javascript" src="<?php echo $this->getSkinUrl('monstroestudio/moip/js/jquery.js') ?>"></script>
|
| 58 |
+
<script type="text/javascript" src="<?php echo $this->getMoipUrl() ?>/transparente/MoipWidget-v2.js" charset="ISO-8859-1"></script>
|
| 59 |
+
<script type="text/javascript">
|
| 60 |
+
var settings = <?php echo $this->getMoipJson() ?>;
|
| 61 |
+
if(settings.Forma == undefined){
|
| 62 |
+
document.location = '<?php echo $this->getUrl() ?>';
|
| 63 |
+
}else{
|
| 64 |
+
window.onbeforeunload = function (e) {
|
| 65 |
+
e = e || window.event;
|
| 66 |
+
if(e){
|
| 67 |
+
e.returnValue = 'Ao recarregar está pagina você sera redirecionado para a home do site';
|
| 68 |
+
}
|
| 69 |
+
return 'Ao recarregar está pagina você sera redirecionado para a home do site';
|
| 70 |
+
};
|
| 71 |
+
}
|
| 72 |
+
MoipWidget(settings);
|
| 73 |
+
|
| 74 |
+
var FUNCAO_DE_SUCESSO = function(data){
|
| 75 |
+
console.log(data);
|
| 76 |
+
if(data.url){
|
| 77 |
+
$('moip-url').innerHTML = data.url;
|
| 78 |
+
}
|
| 79 |
+
$('retorno-moip').slideDown();
|
| 80 |
+
$('moip-method').innerHTML = settings.Forma;
|
| 81 |
+
if(data.Status){
|
| 82 |
+
$('statusPagamento').innerHTML = data.Status;
|
| 83 |
+
}else{
|
| 84 |
+
$('statusPagamento').innerHTML = data.StatusPagamento;
|
| 85 |
+
}
|
| 86 |
+
if(data.CodigoMoIP){
|
| 87 |
+
$('codigoMoipValue').innerHTML = data.CodigoMoIP;
|
| 88 |
+
}else{
|
| 89 |
+
$('codigoMoip').hide();
|
| 90 |
+
}
|
| 91 |
+
if(settings.Forma !== 'CartaoCredito'){
|
| 92 |
+
|
| 93 |
+
$('pagarTransferencia').href = data.url;
|
| 94 |
+
}else{
|
| 95 |
+
if(data.Parcelas){
|
| 96 |
+
$('parcelasMoip').show();
|
| 97 |
+
}
|
| 98 |
+
if(data.Instituicao){
|
| 99 |
+
$('bandeiraMoip').show();
|
| 100 |
+
}
|
| 101 |
+
$('parcelasMoipValue').innerHTML = data.Parcelas;
|
| 102 |
+
$('bandeiraMoipValue').innerHTML = data.Instituicao;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
console.log(data);
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
var FUNCAO_DE_FALHA = function(data) {
|
| 109 |
+
console.log(data);
|
| 110 |
+
$('moip-method').innerHTML = settings.Forma;
|
| 111 |
+
$('retorno-moip').slideDown();
|
| 112 |
+
$('error-moip').show();
|
| 113 |
+
$('codigoMoip').innerHTML = data.Codigo;
|
| 114 |
+
$('statusPagamento').innerHTML = data.StatusPagamento;
|
| 115 |
+
$('errorMessage').innerHTML = data.Mensagem;
|
| 116 |
+
};
|
| 117 |
+
</script>
|
lib/Moip/Moip.php
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Library to help PHP users of Moip's API
|
| 5 |
+
*
|
| 6 |
+
* @author Herberth Amaral
|
| 7 |
+
* @author Wesley Willians
|
| 8 |
+
* @author Alê Borba
|
| 9 |
+
* @author Vagner Fiuza Vieira
|
| 10 |
+
* @author Paulo Cesar
|
| 11 |
+
* @version 1.6.2
|
| 12 |
+
* @license <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Moip's API abstraction class
|
| 17 |
+
*
|
| 18 |
+
* Class to use for all abstraction of Moip's API
|
| 19 |
+
* @package Moip
|
| 20 |
+
*/
|
| 21 |
+
class Moip_Moip {
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Encoding of the page
|
| 25 |
+
*
|
| 26 |
+
* @var string
|
| 27 |
+
*/
|
| 28 |
+
public $encoding = 'UTF-8';
|
| 29 |
+
/**
|
| 30 |
+
* Associative array with two keys. 'key'=>'your_key','token'=>'your_token'
|
| 31 |
+
*
|
| 32 |
+
* @var array
|
| 33 |
+
*/
|
| 34 |
+
protected $credential;
|
| 35 |
+
/**
|
| 36 |
+
* Define the payment's reason
|
| 37 |
+
*
|
| 38 |
+
* @var string
|
| 39 |
+
*/
|
| 40 |
+
protected $reason;
|
| 41 |
+
/**
|
| 42 |
+
* The application's environment
|
| 43 |
+
*
|
| 44 |
+
* @var MoipEnvironment
|
| 45 |
+
*/
|
| 46 |
+
protected $environment = null;
|
| 47 |
+
/**
|
| 48 |
+
* Transaction's unique ID
|
| 49 |
+
*
|
| 50 |
+
* @var string
|
| 51 |
+
*/
|
| 52 |
+
protected $uniqueID;
|
| 53 |
+
/**
|
| 54 |
+
* Associative array of payment's way
|
| 55 |
+
*
|
| 56 |
+
* @var array
|
| 57 |
+
*/
|
| 58 |
+
protected $payment_ways = array('billet' => 'BoletoBancario',
|
| 59 |
+
'financing' => 'FinanciamentoBancario',
|
| 60 |
+
'debit' => 'DebitoBancario',
|
| 61 |
+
'creditCard' => 'CartaoCredito',
|
| 62 |
+
'debitCard' => 'CartaoDebito');
|
| 63 |
+
/**
|
| 64 |
+
* Associative array of payment's institutions
|
| 65 |
+
*
|
| 66 |
+
* @var array
|
| 67 |
+
*/
|
| 68 |
+
protected $institution = array('moip' => 'MoIP',
|
| 69 |
+
'visa' => 'Visa',
|
| 70 |
+
'american_express' => 'AmericanExpress',
|
| 71 |
+
'mastercard' => 'Mastercard',
|
| 72 |
+
'diners' => 'Diners',
|
| 73 |
+
'banco_brasil' => 'BancoDoBrasil',
|
| 74 |
+
'bradesco' => 'Bradesco',
|
| 75 |
+
'itau' => 'Itau',
|
| 76 |
+
'real' => 'BancoReal',
|
| 77 |
+
'unibanco' => 'Unibanco',
|
| 78 |
+
'aura' => 'Aura',
|
| 79 |
+
'hipercard' => 'Hipercard',
|
| 80 |
+
'paggo' => 'Paggo', //oi paggo
|
| 81 |
+
'banrisul' => 'Banrisul'
|
| 82 |
+
);
|
| 83 |
+
/**
|
| 84 |
+
* Associative array of delivery's type
|
| 85 |
+
*
|
| 86 |
+
* @var array
|
| 87 |
+
*/
|
| 88 |
+
protected $delivery_type = array('proprio' => 'Proprio', 'correios' => 'Correios');
|
| 89 |
+
/**
|
| 90 |
+
* Associative array with type of delivery's time
|
| 91 |
+
*
|
| 92 |
+
* @var array
|
| 93 |
+
*/
|
| 94 |
+
protected $delivery_type_time = array('corridos' => 'Corridos', 'uteis' => 'Uteis');
|
| 95 |
+
/**
|
| 96 |
+
* Payment method
|
| 97 |
+
*
|
| 98 |
+
* @var array
|
| 99 |
+
*/
|
| 100 |
+
protected $payment_method;
|
| 101 |
+
/**
|
| 102 |
+
* Arguments of payment method
|
| 103 |
+
*
|
| 104 |
+
* @var array
|
| 105 |
+
*/
|
| 106 |
+
protected $payment_method_args;
|
| 107 |
+
/**
|
| 108 |
+
* Payment's type
|
| 109 |
+
*
|
| 110 |
+
* @var string
|
| 111 |
+
*/
|
| 112 |
+
protected $payment_type;
|
| 113 |
+
/**
|
| 114 |
+
* Associative array with payer's information
|
| 115 |
+
*
|
| 116 |
+
* @var array
|
| 117 |
+
*/
|
| 118 |
+
protected $payer;
|
| 119 |
+
/**
|
| 120 |
+
* Server's answer
|
| 121 |
+
*
|
| 122 |
+
* @var MoipResponse
|
| 123 |
+
*/
|
| 124 |
+
public $answer;
|
| 125 |
+
/**
|
| 126 |
+
* The transaction's value
|
| 127 |
+
*
|
| 128 |
+
* @var float
|
| 129 |
+
*/
|
| 130 |
+
protected $value;
|
| 131 |
+
/**
|
| 132 |
+
* Simple XML object
|
| 133 |
+
*
|
| 134 |
+
* @var SimpleXMLElement
|
| 135 |
+
*/
|
| 136 |
+
protected $xml;
|
| 137 |
+
/**
|
| 138 |
+
* Simple XML object
|
| 139 |
+
*
|
| 140 |
+
* @var object
|
| 141 |
+
*/
|
| 142 |
+
public $errors;
|
| 143 |
+
/**
|
| 144 |
+
* @var array
|
| 145 |
+
*/
|
| 146 |
+
protected $payment_way = array();
|
| 147 |
+
/**
|
| 148 |
+
* @var float
|
| 149 |
+
*/
|
| 150 |
+
protected $adds;
|
| 151 |
+
/**
|
| 152 |
+
* @var float
|
| 153 |
+
*/
|
| 154 |
+
protected $deduction;
|
| 155 |
+
/**
|
| 156 |
+
* Method construct
|
| 157 |
+
*
|
| 158 |
+
* @access public
|
| 159 |
+
*/
|
| 160 |
+
public function __construct() {
|
| 161 |
+
$this->setEnvironment();
|
| 162 |
+
|
| 163 |
+
if (!$this->payment_type) {
|
| 164 |
+
$this->payment_type = 'Basic';
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
$this->initXMLObject();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
private function convert_encoding($text, $post = false)
|
| 171 |
+
{
|
| 172 |
+
if ($post)
|
| 173 |
+
{
|
| 174 |
+
return mb_convert_encoding($text, 'UTF-8');
|
| 175 |
+
}
|
| 176 |
+
else
|
| 177 |
+
{
|
| 178 |
+
/* No need to convert if its already in utf-8 */
|
| 179 |
+
if ($this->encoding === 'UTF-8')
|
| 180 |
+
{
|
| 181 |
+
return $text;
|
| 182 |
+
}
|
| 183 |
+
return mb_convert_encoding($text, $this->encoding, 'UTF-8');
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* Method initXMLObject()
|
| 189 |
+
*
|
| 190 |
+
* Start a new XML structure for the requests
|
| 191 |
+
*
|
| 192 |
+
* @return void
|
| 193 |
+
* @access private
|
| 194 |
+
*/
|
| 195 |
+
private function initXMLObject() {
|
| 196 |
+
$this->xml = new SimpleXmlElement('<?xml version="1.0" encoding="utf-8" ?><EnviarInstrucao></EnviarInstrucao>');
|
| 197 |
+
$this->xml->addChild('InstrucaoUnica');
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/**
|
| 201 |
+
* Method setPaymentType()
|
| 202 |
+
*
|
| 203 |
+
* Define the payment's type between 'Basic' or 'Identification'
|
| 204 |
+
*
|
| 205 |
+
* @param string $tipo Can be 'Basic' or 'Identification'
|
| 206 |
+
* @return Moip
|
| 207 |
+
* @access public
|
| 208 |
+
*/
|
| 209 |
+
public function setPaymentType($tipo) {
|
| 210 |
+
if ($tipo == 'Basic' || $tipo == 'Identification') {
|
| 211 |
+
$this->payment_type = $tipo;
|
| 212 |
+
} else {
|
| 213 |
+
$this->setError("Error: The variable type must contain values 'Basic' or 'Identification'");
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
return $this;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* Method setCredential()
|
| 221 |
+
*
|
| 222 |
+
* Set the credentials(key,token) required for the API authentication.
|
| 223 |
+
*
|
| 224 |
+
* @param array $credential Array with the credentials token and key
|
| 225 |
+
* @return Moip
|
| 226 |
+
* @access public
|
| 227 |
+
*/
|
| 228 |
+
public function setCredential($credential) {
|
| 229 |
+
if (!isset($credential['token']) or
|
| 230 |
+
!isset($credential['key']) or
|
| 231 |
+
strlen($credential['token']) != 32 or
|
| 232 |
+
strlen($credential['key']) != 40)
|
| 233 |
+
$this->setError("Error: credential invalid");
|
| 234 |
+
|
| 235 |
+
$this->credential = $credential;
|
| 236 |
+
return $this;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
/**
|
| 240 |
+
* Method setEnvironment()
|
| 241 |
+
*
|
| 242 |
+
* Define the environment for the API utilization.
|
| 243 |
+
*
|
| 244 |
+
* @param bool $testing If true, will use the sandbox environment
|
| 245 |
+
* @return Moip
|
| 246 |
+
*/
|
| 247 |
+
public function setEnvironment($testing = false) {
|
| 248 |
+
if (empty($this->environment))
|
| 249 |
+
{
|
| 250 |
+
$this->environment = new Moip_MoipEnvironment();
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if ($testing) {
|
| 254 |
+
$this->environment->name = "Sandbox";
|
| 255 |
+
$this->environment->base_url = "https://desenvolvedor.moip.com.br/sandbox";
|
| 256 |
+
} else {
|
| 257 |
+
$this->environment->name = "Produção";
|
| 258 |
+
$this->environment->base_url = "https://www.moip.com.br";
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
return $this;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
/**
|
| 265 |
+
* Method validate()
|
| 266 |
+
*
|
| 267 |
+
* Make the data validation
|
| 268 |
+
*
|
| 269 |
+
* @param string $validateType Identification or Basic, defaults to Basic
|
| 270 |
+
* @return Moip
|
| 271 |
+
* @access public
|
| 272 |
+
*/
|
| 273 |
+
public function validate($validateType = "Basic") {
|
| 274 |
+
|
| 275 |
+
$this->setPaymentType($validateType);
|
| 276 |
+
|
| 277 |
+
if (!isset($this->credential) or
|
| 278 |
+
!isset($this->reason) or
|
| 279 |
+
!isset($this->uniqueID))
|
| 280 |
+
$this->setError("[setCredential], [setReason] and [setUniqueID] are required");
|
| 281 |
+
|
| 282 |
+
$payer = $this->payer;
|
| 283 |
+
|
| 284 |
+
if ($this->payment_type == 'Identification') {
|
| 285 |
+
$varNotSeted = '';
|
| 286 |
+
|
| 287 |
+
$dataValidate = array('name',
|
| 288 |
+
'email',
|
| 289 |
+
'payerId',
|
| 290 |
+
'billingAddress');
|
| 291 |
+
|
| 292 |
+
$dataValidateAddress = array('address',
|
| 293 |
+
'number',
|
| 294 |
+
'complement',
|
| 295 |
+
'neighborhood',
|
| 296 |
+
'city',
|
| 297 |
+
'state',
|
| 298 |
+
'country',
|
| 299 |
+
'zipCode',
|
| 300 |
+
'phone');
|
| 301 |
+
|
| 302 |
+
foreach ($dataValidate as $key) {
|
| 303 |
+
if (!isset($payer[$key])) {
|
| 304 |
+
$varNotSeted .= ' [' . $key . '] ';
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
foreach ($dataValidateAddress as $key) {
|
| 309 |
+
if (!isset($payer['billingAddress'][$key])) {
|
| 310 |
+
$varNotSeted .= ' [' . $key . '] ';
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
if ($varNotSeted !== '') {
|
| 315 |
+
$this->setError('Error: The following data required were not informed: ' . $varNotSeted . '.');
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
return $this;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
/**
|
| 322 |
+
* Method setUniqueID()
|
| 323 |
+
*
|
| 324 |
+
* Set the unique ID for the transaction
|
| 325 |
+
*
|
| 326 |
+
* @param int $id Unique ID for each transaction
|
| 327 |
+
* @return Moip
|
| 328 |
+
* @access public
|
| 329 |
+
*/
|
| 330 |
+
public function setUniqueID($id) {
|
| 331 |
+
$this->uniqueID = $id;
|
| 332 |
+
$this->xml->InstrucaoUnica->addChild('IdProprio', $this->uniqueID);
|
| 333 |
+
|
| 334 |
+
return $this;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* Method setReason()
|
| 339 |
+
*
|
| 340 |
+
* Set the short description of transaction. eg. Order Number.
|
| 341 |
+
*
|
| 342 |
+
* @param string $reason The reason fo transaction
|
| 343 |
+
* @return Moip
|
| 344 |
+
* @access public
|
| 345 |
+
*/
|
| 346 |
+
public function setReason($reason) {
|
| 347 |
+
$this->reason = $reason;
|
| 348 |
+
$this->xml->InstrucaoUnica->addChild('Razao', $this->reason);
|
| 349 |
+
|
| 350 |
+
return $this;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
/**
|
| 354 |
+
* Method addPaymentWay()
|
| 355 |
+
*
|
| 356 |
+
* Add a payment's method
|
| 357 |
+
*
|
| 358 |
+
* @param string $way The payment method. Options: 'billet','financing','debit','creditCard','debitCard'.
|
| 359 |
+
* @return Moip
|
| 360 |
+
* @access public
|
| 361 |
+
*/
|
| 362 |
+
public function addPaymentWay($way) {
|
| 363 |
+
if (!isset($this->payment_ways[$way]))
|
| 364 |
+
$this->setError("Error: Payment method unavailable");
|
| 365 |
+
else
|
| 366 |
+
$this->payment_way[] = $way;
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
$instrucao = $this->xml->InstrucaoUnica;
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
$formas = (!isset($instrucao->FormasPagamento)) ? $instrucao->addChild('FormasPagamento') : $instrucao->FormasPagamento;
|
| 373 |
+
|
| 374 |
+
if (!empty($this->payment_way))
|
| 375 |
+
$formas->addChild('FormaPagamento', $this->payment_ways[$way]);
|
| 376 |
+
|
| 377 |
+
return $this;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
/**
|
| 381 |
+
* Method billetConf()
|
| 382 |
+
*
|
| 383 |
+
* Add a payment's method
|
| 384 |
+
*
|
| 385 |
+
* @param int $expiration expiration in days or dateTime.
|
| 386 |
+
* @param boolean $workingDays expiration should be counted in working days?
|
| 387 |
+
* @param array $instructions Additional payment instructions can be array of message or a message in string
|
| 388 |
+
* @param string $uriLogo URL of the image to be displayed on docket (75x40)
|
| 389 |
+
* @return void
|
| 390 |
+
* @access public
|
| 391 |
+
*/
|
| 392 |
+
public function setBilletConf($expiration, $workingDays=false, $instructions = null, $uriLogo = null) {
|
| 393 |
+
|
| 394 |
+
if (!isset($this->xml->InstrucaoUnica->Boleto)) {
|
| 395 |
+
$this->xml->InstrucaoUnica->addChild('Boleto');
|
| 396 |
+
|
| 397 |
+
if (is_numeric($expiration)) {
|
| 398 |
+
$this->xml->InstrucaoUnica->Boleto->addChild('DiasExpiracao', $expiration);
|
| 399 |
+
|
| 400 |
+
if ($workingDays)
|
| 401 |
+
$this->xml->InstrucaoUnica->Boleto->DiasExpiracao->addAttribute('Tipo', 'Uteis');
|
| 402 |
+
else
|
| 403 |
+
$this->xml->InstrucaoUnica->Boleto->DiasExpiracao->addAttribute('Tipo', 'Corridos');
|
| 404 |
+
}else {
|
| 405 |
+
$this->xml->InstrucaoUnica->Boleto->addChild('DataVencimento', $expiration);
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
if (isset($instructions)) {
|
| 409 |
+
if (is_array($instructions)) {
|
| 410 |
+
$numeroInstrucoes = 1;
|
| 411 |
+
foreach ($instructions as $instrucaostr) {
|
| 412 |
+
$this->xml->InstrucaoUnica->Boleto->addChild('Instrucao' . $numeroInstrucoes, $instrucaostr);
|
| 413 |
+
$numeroInstrucoes++;
|
| 414 |
+
}
|
| 415 |
+
} else {
|
| 416 |
+
$this->xml->InstrucaoUnica->Boleto->addChild('Instrucao1', $instructions);
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
if (isset($uriLogo))
|
| 421 |
+
$this->xml->InstrucaoUnica->Boleto->addChild('URLLogo', $uriLogo);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
return $this;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/**
|
| 428 |
+
* Method setPayer()
|
| 429 |
+
*
|
| 430 |
+
* Set contacts informations for the payer.
|
| 431 |
+
*
|
| 432 |
+
* @param array $payer Contact information for the payer.
|
| 433 |
+
* @return Moip
|
| 434 |
+
* @access public
|
| 435 |
+
*/
|
| 436 |
+
public function setPayer($payer) {
|
| 437 |
+
$this->payer = $payer;
|
| 438 |
+
|
| 439 |
+
if (!empty($this->payer)) {
|
| 440 |
+
$p = $this->payer;
|
| 441 |
+
$this->xml->InstrucaoUnica->addChild('Pagador');
|
| 442 |
+
(isset($p['name'])) ? $this->xml->InstrucaoUnica->Pagador->addChild('Nome', $this->payer['name']) : null;
|
| 443 |
+
(isset($p['email'])) ? $this->xml->InstrucaoUnica->Pagador->addChild('Email', $this->payer['email']) : null;
|
| 444 |
+
(isset($p['payerId'])) ? $this->xml->InstrucaoUnica->Pagador->addChild('IdPagador', $this->payer['payerId']) : null;
|
| 445 |
+
(isset($p['identity'])) ? $this->xml->InstrucaoUnica->Pagador->addChild('Identidade', $this->payer['identity']) : null;
|
| 446 |
+
(isset($p['phone'])) ? $this->xml->InstrucaoUnica->Pagador->addChild('TelefoneCelular', $this->payer['phone']) : null;
|
| 447 |
+
|
| 448 |
+
$p = $this->payer['billingAddress'];
|
| 449 |
+
$this->xml->InstrucaoUnica->Pagador->addChild('EnderecoCobranca');
|
| 450 |
+
(isset($p['address'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Logradouro', $this->payer['billingAddress']['address']) : null;
|
| 451 |
+
|
| 452 |
+
(isset($p['number'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Numero', $this->payer['billingAddress']['number']) : null;
|
| 453 |
+
|
| 454 |
+
(isset($p['complement'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Complemento', $this->payer['billingAddress']['complement']) : null;
|
| 455 |
+
|
| 456 |
+
(isset($p['neighborhood'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Bairro', $this->payer['billingAddress']['neighborhood']) : null;
|
| 457 |
+
|
| 458 |
+
(isset($p['city'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Cidade', $this->payer['billingAddress']['city']) : null;
|
| 459 |
+
|
| 460 |
+
(isset($p['state'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Estado', $this->payer['billingAddress']['state']) : null;
|
| 461 |
+
|
| 462 |
+
(isset($p['country'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('Pais', $this->payer['billingAddress']['country']) : null;
|
| 463 |
+
|
| 464 |
+
(isset($p['zipCode'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('CEP', $this->payer['billingAddress']['zipCode']) : null;
|
| 465 |
+
|
| 466 |
+
(isset($p['phone'])) ? $this->xml->InstrucaoUnica->Pagador->EnderecoCobranca->addChild('TelefoneFixo', $this->payer['billingAddress']['phone']) : null;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
return $this;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
/**
|
| 473 |
+
* Method setValue()
|
| 474 |
+
*
|
| 475 |
+
* Set the transaction's value
|
| 476 |
+
*
|
| 477 |
+
* @param float $value The transaction's value
|
| 478 |
+
* @return Moip
|
| 479 |
+
* @access public
|
| 480 |
+
*/
|
| 481 |
+
public function setValue($value) {
|
| 482 |
+
$this->value = $value;
|
| 483 |
+
|
| 484 |
+
if (empty($this->value))
|
| 485 |
+
$this->setError('Error: The transaction amount must be specified.');
|
| 486 |
+
|
| 487 |
+
$this->xml->InstrucaoUnica->addChild('Valores')
|
| 488 |
+
->addChild('Valor', $this->value)
|
| 489 |
+
->addAttribute('moeda', 'BRL');
|
| 490 |
+
|
| 491 |
+
return $this;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
/**
|
| 495 |
+
* Method setAdds()
|
| 496 |
+
*
|
| 497 |
+
* Adds a value on payment. Can be used for collecting fines, shipping and other
|
| 498 |
+
*
|
| 499 |
+
* @param float $value The value to add.
|
| 500 |
+
* @return Moip
|
| 501 |
+
* @access public
|
| 502 |
+
*/
|
| 503 |
+
public function setAdds($value) {
|
| 504 |
+
$this->adds = $value;
|
| 505 |
+
|
| 506 |
+
if (isset($this->adds)) {
|
| 507 |
+
$this->xml->InstrucaoUnica->Valores->addChild('Acrescimo', $this->adds)
|
| 508 |
+
->addAttribute('moeda', 'BRL');
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
return $this;
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
/**
|
| 515 |
+
* Method setDeduct()
|
| 516 |
+
*
|
| 517 |
+
* Deducts a payment amount. It is mainly used for discounts.
|
| 518 |
+
*
|
| 519 |
+
* @param float $value The value to deduct
|
| 520 |
+
* @return Moip
|
| 521 |
+
* @access public
|
| 522 |
+
*/
|
| 523 |
+
public function setDeduct($value) {
|
| 524 |
+
$this->deduction = $value;
|
| 525 |
+
|
| 526 |
+
if (isset($this->deduction)) {
|
| 527 |
+
$this->xml->InstrucaoUnica->Valores->addChild('Deducao', $this->deduction)
|
| 528 |
+
->addAttribute('moeda', 'BRL');
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
return $this;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
/**
|
| 535 |
+
* Method addMessage()
|
| 536 |
+
*
|
| 537 |
+
* Add a message in the instruction to be displayed to the payer.
|
| 538 |
+
*
|
| 539 |
+
* @param string $msg Message to be displayed.
|
| 540 |
+
* @return Moip
|
| 541 |
+
* @access public
|
| 542 |
+
*/
|
| 543 |
+
public function addMessage($msg) {
|
| 544 |
+
if (!isset($this->xml->InstrucaoUnica->Mensagens)) {
|
| 545 |
+
$this->xml->InstrucaoUnica->addChild('Mensagens');
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
$this->xml->InstrucaoUnica->Mensagens->addChild('Mensagem', $msg);
|
| 549 |
+
return $this;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
/**
|
| 553 |
+
* Method setReturnURL()
|
| 554 |
+
*
|
| 555 |
+
* Set the return URL, which redirects the client after payment.
|
| 556 |
+
*
|
| 557 |
+
* @param string $url Return URL
|
| 558 |
+
* @return Moip
|
| 559 |
+
* @access public
|
| 560 |
+
*/
|
| 561 |
+
public function setReturnURL($url) {
|
| 562 |
+
if (!isset($this->xml->InstrucaoUnica->URLRetorno)) {
|
| 563 |
+
$this->xml->InstrucaoUnica->addChild('URLRetorno', $url);
|
| 564 |
+
}
|
| 565 |
+
return $this;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
/**
|
| 569 |
+
* Method setNotificationURL()
|
| 570 |
+
*
|
| 571 |
+
* Set the notification URL, which sends information about changes in payment status
|
| 572 |
+
*
|
| 573 |
+
* @param string $url Notification URL
|
| 574 |
+
* @access public
|
| 575 |
+
*/
|
| 576 |
+
public function setNotificationURL($url) {
|
| 577 |
+
if (!isset($this->xml->InstrucaoUnica->URLNotificacao)) {
|
| 578 |
+
$this->xml->InstrucaoUnica->addChild('URLNotificacao', $url);
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
/**
|
| 583 |
+
* Method setError()
|
| 584 |
+
*
|
| 585 |
+
* Set Erroe alert
|
| 586 |
+
*
|
| 587 |
+
* @param String $error Error alert
|
| 588 |
+
* @return Moip
|
| 589 |
+
* @access public
|
| 590 |
+
*/
|
| 591 |
+
public function setError($error) {
|
| 592 |
+
$this->errors = $error;
|
| 593 |
+
|
| 594 |
+
return $this;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
/**
|
| 598 |
+
* Method addComission()
|
| 599 |
+
*
|
| 600 |
+
* Allows to specify commissions on the payment, like fixed values or percent.
|
| 601 |
+
*
|
| 602 |
+
* @param string $reason reason for commissioning
|
| 603 |
+
* @param string $receiver login Moip the secondary receiver
|
| 604 |
+
* @param number $value value of the division of payment
|
| 605 |
+
* @param boolean $percentageValue percentage value should be
|
| 606 |
+
* @param boolean $ratePayer this secondary recipient will pay the fee Moip
|
| 607 |
+
* @return Moip
|
| 608 |
+
* @access public
|
| 609 |
+
*/
|
| 610 |
+
public function addComission($reason, $receiver, $value, $percentageValue=false, $ratePayer=false) {
|
| 611 |
+
|
| 612 |
+
if (!isset($this->xml->InstrucaoUnica->Comissoes))
|
| 613 |
+
$this->xml->InstrucaoUnica->addChild('Comissoes');
|
| 614 |
+
|
| 615 |
+
if (is_numeric($value)) {
|
| 616 |
+
|
| 617 |
+
$split = $this->xml->InstrucaoUnica->Comissoes->addChild('Comissionamento');
|
| 618 |
+
$split->addChild('Comissionado')->addChild('LoginMoIP', $receiver);
|
| 619 |
+
$split->addChild('Razao', $reason);
|
| 620 |
+
|
| 621 |
+
if ($percentageValue == false)
|
| 622 |
+
$split->addChild('ValorFixo', $value);
|
| 623 |
+
if ($percentageValue == true)
|
| 624 |
+
$split->addChild('ValorPercentual', $value);
|
| 625 |
+
if ($ratePayer == true)
|
| 626 |
+
$this->xml->InstrucaoUnica->Comissoes->addChild('PagadorTaxa')->addChild('LoginMoIP', $receiver);
|
| 627 |
+
}else {
|
| 628 |
+
$this->setError('Error: Value must be numeric.');
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
return $this;
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
/**
|
| 635 |
+
* Method addParcel()
|
| 636 |
+
*
|
| 637 |
+
* Allows to add a order to parceling.
|
| 638 |
+
*
|
| 639 |
+
* @param int $min The minimum number of parcels.
|
| 640 |
+
* @param int $max The maximum number of parcels.
|
| 641 |
+
* @param float $rate The percentual value of rates
|
| 642 |
+
* @param boolean $transfer "true" defines the amount of interest charged by MoIP installment to be paid by the payer
|
| 643 |
+
* @return Moip
|
| 644 |
+
* @access public
|
| 645 |
+
*/
|
| 646 |
+
public function addParcel($min, $max, $rate=null, $transfer=false, $recebimento = 'AVista') {
|
| 647 |
+
if (!isset($this->xml->InstrucaoUnica->Parcelamentos)) {
|
| 648 |
+
$this->xml->InstrucaoUnica->addChild('Parcelamentos');
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
$parcela = $this->xml->InstrucaoUnica->Parcelamentos->addChild('Parcelamento');
|
| 652 |
+
if (is_numeric($min) && $min <= 12)
|
| 653 |
+
$parcela->addChild('MinimoParcelas', $min);
|
| 654 |
+
else
|
| 655 |
+
$this->setError('Error: Minimum parcel can not be greater than 12.');
|
| 656 |
+
|
| 657 |
+
if (is_numeric($max) && $max <= 12)
|
| 658 |
+
$parcela->addChild('MaximoParcelas', $max);
|
| 659 |
+
else
|
| 660 |
+
$this->setError('Error: Maximum amount can not be greater than 12.');
|
| 661 |
+
|
| 662 |
+
$parcela->addChild('Recebimento', $recebimento);
|
| 663 |
+
|
| 664 |
+
if ($transfer === false) {
|
| 665 |
+
if (isset($rate)) {
|
| 666 |
+
if (is_numeric($rate))
|
| 667 |
+
$parcela->addChild('Juros', $rate);
|
| 668 |
+
else
|
| 669 |
+
$this->setError('Error: Rate must be numeric');
|
| 670 |
+
}
|
| 671 |
+
}else {
|
| 672 |
+
if (is_bool($transfer))
|
| 673 |
+
$parcela->addChild('Repassar', $transfer);
|
| 674 |
+
else
|
| 675 |
+
$this->setError('Error: Transfer must be boolean');
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
return $this;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
/**
|
| 682 |
+
* Method setReceiving()
|
| 683 |
+
*
|
| 684 |
+
* Allows to add a order to parceling.
|
| 685 |
+
*
|
| 686 |
+
* @param string $receiver login Moip the secondary receiver
|
| 687 |
+
* @return Moip
|
| 688 |
+
* @access public
|
| 689 |
+
*/
|
| 690 |
+
public function setReceiver($receiver, $nickname) {
|
| 691 |
+
if (!isset($this->xml->InstrucaoUnica->Recebedor)) {
|
| 692 |
+
$node = $this->xml->InstrucaoUnica->addChild('Recebedor');
|
| 693 |
+
$node->addChild('LoginMoIP', $receiver);
|
| 694 |
+
$node->addChild('Apelido', $nickname);
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
return $this;
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
/**
|
| 701 |
+
* Method getXML()
|
| 702 |
+
*
|
| 703 |
+
* Returns the XML that is generated. Useful for debugging.
|
| 704 |
+
*
|
| 705 |
+
* @return string
|
| 706 |
+
* @access public
|
| 707 |
+
*/
|
| 708 |
+
public function getXML() {
|
| 709 |
+
|
| 710 |
+
if ($this->payment_type == "Identification")
|
| 711 |
+
$this->xml->InstrucaoUnica->addAttribute('TipoValidacao', 'Transparente');
|
| 712 |
+
|
| 713 |
+
$return = $this->convert_encoding($this->xml->asXML(), true);
|
| 714 |
+
return str_ireplace("\n", "", $return);
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
/**
|
| 718 |
+
* Method send()
|
| 719 |
+
*
|
| 720 |
+
* Send the request to the server
|
| 721 |
+
*
|
| 722 |
+
* @param object $client The server's connection
|
| 723 |
+
* @return MoipResponse
|
| 724 |
+
* @access public
|
| 725 |
+
*/
|
| 726 |
+
public function send($client=null) {
|
| 727 |
+
$this->validate();
|
| 728 |
+
|
| 729 |
+
if ($client == null)
|
| 730 |
+
$client = new Moip_MoipClient();
|
| 731 |
+
|
| 732 |
+
$url = $this->environment->base_url . '/ws/alpha/EnviarInstrucao/Unica';
|
| 733 |
+
|
| 734 |
+
return $this->answer = $client->curlPost($this->credential['token'] . ':' . $this->credential['key'],
|
| 735 |
+
$this->getXML(),
|
| 736 |
+
$url, $this->errors);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
/**
|
| 740 |
+
* Method getAnswer()
|
| 741 |
+
*
|
| 742 |
+
* Gets the server's answer
|
| 743 |
+
* @param boolean $return_xml_as_string Return the answer XMl string
|
| 744 |
+
* @return MoipResponse|string
|
| 745 |
+
* @access public
|
| 746 |
+
*/
|
| 747 |
+
public function getAnswer($return_xml_as_string = false) {
|
| 748 |
+
if ($this->answer->response == true) {
|
| 749 |
+
if ($return_xml_as_string) {
|
| 750 |
+
return $this->answer->xml;
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
$xml = new SimpleXmlElement($this->answer->xml);
|
| 754 |
+
|
| 755 |
+
return new Moip_MoipResponse(array(
|
| 756 |
+
'response' => $xml->Resposta->Status == 'Sucesso' ? true : false,
|
| 757 |
+
'error' => $xml->Resposta->Status == 'Falha' ? $this->convert_encoding((string)$xml->Resposta->Erro) : false,
|
| 758 |
+
'token' => (string) $xml->Resposta->Token,
|
| 759 |
+
'payment_url' => $xml->Resposta->Status == 'Sucesso' ? (string) $this->environment->base_url . "/Instrucao.do?token=" . (string) $xml->Resposta->Token : false,
|
| 760 |
+
));
|
| 761 |
+
} else {
|
| 762 |
+
return $this->answer->error;
|
| 763 |
+
}
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
/**
|
| 767 |
+
* Method verifyParcelValues()
|
| 768 |
+
*
|
| 769 |
+
* Get all informations about the parcelling of user defined by $login_moip
|
| 770 |
+
*
|
| 771 |
+
* @param string $login The client's login for Moip services
|
| 772 |
+
* @param int $maxParcel The total parcels
|
| 773 |
+
* @param float $rate The rate's percents of the parcelling.
|
| 774 |
+
* @param float $simulatedValue The value for simulation
|
| 775 |
+
* @return array
|
| 776 |
+
* @access public
|
| 777 |
+
*/
|
| 778 |
+
public function queryParcel($login, $maxParcel, $rate, $simulatedValue) {
|
| 779 |
+
if (!isset($this->credential))
|
| 780 |
+
$this->setError("You must specify the credentials (token / key) and enriroment");
|
| 781 |
+
|
| 782 |
+
|
| 783 |
+
$client = new Moip_MoipClient();
|
| 784 |
+
|
| 785 |
+
$url = $this->environment->base_url . "/ws/alpha/ChecarValoresParcelamento/$login/$maxParcel/$rate/$simulatedValue";
|
| 786 |
+
$credential = $this->credential['token'] . ':' . $this->credential['key'];
|
| 787 |
+
$answer = $client->curlGet($credential, $url, $this->errors);
|
| 788 |
+
|
| 789 |
+
if ($answer->response) {
|
| 790 |
+
$xml = new SimpleXmlElement($answer->xml);
|
| 791 |
+
|
| 792 |
+
if ($xml->Resposta->Status == "Sucesso")
|
| 793 |
+
$response = true;
|
| 794 |
+
else
|
| 795 |
+
$response = false;
|
| 796 |
+
|
| 797 |
+
$return = array('response' => $response,
|
| 798 |
+
'installment' => array());
|
| 799 |
+
|
| 800 |
+
$i = 1;
|
| 801 |
+
foreach ($xml->Resposta->ValorDaParcela as $parcela) {
|
| 802 |
+
$attrib = $parcela->attributes();
|
| 803 |
+
$return['installment']["$i"] = array('total' => (string) $attrib['Total'], 'rate' => (string) $attrib['Juros'], 'value' => (string) $attrib['Valor']);
|
| 804 |
+
$i++;
|
| 805 |
+
}
|
| 806 |
+
return $return;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
return $answer;
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
}
|
lib/Moip/MoipClient.php
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* MoIP's API connection class
|
| 5 |
+
*
|
| 6 |
+
* @author Herberth Amaral
|
| 7 |
+
* @author Paulo Cesar
|
| 8 |
+
* @version 0.0.2
|
| 9 |
+
* @license <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>
|
| 10 |
+
*/
|
| 11 |
+
class Moip_MoipClient {
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* Method send()
|
| 15 |
+
*
|
| 16 |
+
* Send the request to API's server
|
| 17 |
+
*
|
| 18 |
+
* @param string $credentials Token and key to the authentication
|
| 19 |
+
* @param string $xml The XML request
|
| 20 |
+
* @param string $url The server's URL
|
| 21 |
+
* @param string $method Method used to send the request
|
| 22 |
+
* @throws Exception
|
| 23 |
+
* @return MoipResponse
|
| 24 |
+
*/
|
| 25 |
+
public function send($credentials, $xml, $url='https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica', $method='POST') {
|
| 26 |
+
$header[] = "Authorization: Basic " . base64_encode($credentials);
|
| 27 |
+
if (!function_exists('curl_init')){
|
| 28 |
+
throw new Exception('This library needs cURL extension');
|
| 29 |
+
}
|
| 30 |
+
$curl = curl_init();
|
| 31 |
+
curl_setopt($curl, CURLOPT_URL, $url);
|
| 32 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
| 33 |
+
curl_setopt($curl, CURLOPT_USERPWD, $credentials);
|
| 34 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
| 35 |
+
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
|
| 36 |
+
|
| 37 |
+
if ($method == 'POST') curl_setopt($curl, CURLOPT_POST, true);
|
| 38 |
+
|
| 39 |
+
if ($xml != '') curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
|
| 40 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
| 41 |
+
$ret = curl_exec($curl);
|
| 42 |
+
$err = curl_error($curl);
|
| 43 |
+
curl_close($curl);
|
| 44 |
+
|
| 45 |
+
return new Moip_MoipResponse(array('resposta' => $ret, 'erro' => $err));
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* @param string $credentials token / key authentication Moip
|
| 50 |
+
* @param string $xml url request
|
| 51 |
+
* @param string $url url request
|
| 52 |
+
* @param string $error errors
|
| 53 |
+
* @return MoipResponse
|
| 54 |
+
*/
|
| 55 |
+
function curlPost($credentials, $xml, $url, $error=null) {
|
| 56 |
+
|
| 57 |
+
if (!$error) {
|
| 58 |
+
$header[] = "Expect:";
|
| 59 |
+
$header[] = "Authorization: Basic " . base64_encode($credentials);
|
| 60 |
+
|
| 61 |
+
$ch = curl_init();
|
| 62 |
+
$options = array(CURLOPT_URL => $url,
|
| 63 |
+
CURLOPT_HTTPHEADER => $header,
|
| 64 |
+
CURLOPT_SSL_VERIFYPEER => false,
|
| 65 |
+
CURLOPT_POST => true,
|
| 66 |
+
CURLOPT_POSTFIELDS => $xml,
|
| 67 |
+
CURLOPT_RETURNTRANSFER => true,
|
| 68 |
+
CURLINFO_HEADER_OUT => true
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
curl_setopt_array($ch, $options);
|
| 72 |
+
$ret = curl_exec($ch);
|
| 73 |
+
$err = curl_error($ch);
|
| 74 |
+
$info = curl_getinfo($ch);
|
| 75 |
+
curl_close($ch);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
if ($info['http_code'] == "200")
|
| 79 |
+
return new Moip_MoipResponse(array('response' => true, 'error' => null, 'xml' => $ret));
|
| 80 |
+
else if ($info['http_code'] == "500")
|
| 81 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => 'Error processing XML', 'xml' => null));
|
| 82 |
+
else if ($info['http_code'] == "401")
|
| 83 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => 'Authentication failed', 'xml' => null));
|
| 84 |
+
else
|
| 85 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => $err, 'xml' => null));
|
| 86 |
+
} else {
|
| 87 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => $error, 'xml' => null));
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* @param string $credentials token / key authentication Moip
|
| 94 |
+
* @param string $url url request
|
| 95 |
+
* @param string $error errors
|
| 96 |
+
* @return MoipResponse
|
| 97 |
+
*/
|
| 98 |
+
function curlGet($credentials, $url, $error=null) {
|
| 99 |
+
|
| 100 |
+
if (!$error) {
|
| 101 |
+
$header[] = "Expect:";
|
| 102 |
+
$header[] = "Authorization: Basic " . base64_encode($credentials);
|
| 103 |
+
|
| 104 |
+
$ch = curl_init();
|
| 105 |
+
$options = array(CURLOPT_URL => $url,
|
| 106 |
+
CURLOPT_HTTPHEADER => $header,
|
| 107 |
+
CURLOPT_SSL_VERIFYPEER => false,
|
| 108 |
+
CURLOPT_RETURNTRANSFER => true
|
| 109 |
+
);
|
| 110 |
+
|
| 111 |
+
curl_setopt_array($ch, $options);
|
| 112 |
+
$ret = curl_exec($ch);
|
| 113 |
+
$err = curl_error($ch);
|
| 114 |
+
$info = curl_getinfo($ch);
|
| 115 |
+
curl_close($ch);
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if ($info['http_code'] == "200")
|
| 119 |
+
return new Moip_MoipResponse(array('response' => true, 'error' => null, 'xml' => $ret));
|
| 120 |
+
else if ($info['http_code'] == "500")
|
| 121 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => 'Error processing XML', 'xml' => null));
|
| 122 |
+
else if ($info['http_code'] == "401")
|
| 123 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => 'Authentication failed', 'xml' => null));
|
| 124 |
+
else
|
| 125 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => $err, 'xml' => null));
|
| 126 |
+
} else {
|
| 127 |
+
return new Moip_MoipResponse(array('response' => false, 'error' => $error, 'xml' => null));
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
}
|
lib/Moip/MoipEnvironment.php
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Moip_MoipEnvironment {
|
| 4 |
+
public $base_url;
|
| 5 |
+
public $name;
|
| 6 |
+
|
| 7 |
+
function __construct($base_url = '', $name = '')
|
| 8 |
+
{
|
| 9 |
+
$this->base_url = $base_url;
|
| 10 |
+
$this->name = $name;
|
| 11 |
+
}
|
| 12 |
+
}
|
lib/Moip/MoipResponse.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Read-only response
|
| 4 |
+
* @property boolean|string $response
|
| 5 |
+
* @property string $error
|
| 6 |
+
* @property string $xml
|
| 7 |
+
* @property string $payment_url
|
| 8 |
+
* @property string $token
|
| 9 |
+
*/
|
| 10 |
+
class Moip_MoipResponse {
|
| 11 |
+
private $response;
|
| 12 |
+
|
| 13 |
+
function __construct(array $response)
|
| 14 |
+
{
|
| 15 |
+
$this->response = $response;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
function __get($name)
|
| 19 |
+
{
|
| 20 |
+
if (isset($this->response[$name]))
|
| 21 |
+
{
|
| 22 |
+
return $this->response[$name];
|
| 23 |
+
}
|
| 24 |
+
return null;
|
| 25 |
+
}
|
| 26 |
+
}
|
lib/Moip/MoipStatus.php
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
require 'phpQuery/phpQuery.php';
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Verificação de status da conta do MoIP. Atualmente somente com suporte à verificação de saldo e ultimas transações.
|
| 6 |
+
* @author Herberth Amaral
|
| 7 |
+
* @version 0.0.2
|
| 8 |
+
* @package MoIP
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
class moip_MoipStatus
|
| 12 |
+
{
|
| 13 |
+
private $url_login = "https://www.moip.com.br/j_acegi_security_check";
|
| 14 |
+
|
| 15 |
+
function setCredenciais($username,$password)
|
| 16 |
+
{
|
| 17 |
+
|
| 18 |
+
$this->username = $username;
|
| 19 |
+
$this->password = $password;
|
| 20 |
+
return $this;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function getStatus()
|
| 24 |
+
{
|
| 25 |
+
if (!isset($this->username) or !isset($this->password))
|
| 26 |
+
throw new Exception("Usuário ou senha não especificados.");
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
$ch = curl_init($this->url_login);
|
| 30 |
+
curl_setopt($ch, CURLOPT_POST ,1);
|
| 31 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS ,"j_username=$this->username&j_password=$this->password");
|
| 32 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
|
| 33 |
+
curl_setopt($ch, CURLOPT_HEADER ,0);
|
| 34 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
|
| 35 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
| 36 |
+
$page = curl_exec($ch);
|
| 37 |
+
$error = curl_error($ch);
|
| 38 |
+
|
| 39 |
+
if (!empty($error))
|
| 40 |
+
{
|
| 41 |
+
$errno = curl_errno($ch);
|
| 42 |
+
throw new Exception("Ooops, ocorreu um erro ao tentar recuperar os status #$errno: $error");
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if (stristr($page,"Login e senha incorretos"))
|
| 46 |
+
throw new Exception('Login incorreto');
|
| 47 |
+
|
| 48 |
+
$doc = phpQuery::newDocumentHTML($page);
|
| 49 |
+
|
| 50 |
+
$this->saldo = pq('div.textoCinza11 b.textoAzul15')->text();
|
| 51 |
+
$this->saldo_a_receber = pq('div.textoCinza11 b.textoAzul11')->text();
|
| 52 |
+
|
| 53 |
+
$this->ultimas_transacoes = $this->getLastTransactions($page);
|
| 54 |
+
|
| 55 |
+
return $this;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
private function getLastTransactions($page)
|
| 59 |
+
{
|
| 60 |
+
$doc = phpQuery::newDocumentHTML($page);
|
| 61 |
+
|
| 62 |
+
$selector = 'div.conteudo>div:eq(1)>div:eq(1)>div:eq(1)>div:eq(0) div.box table[cellpadding=5]>tbody tr';
|
| 63 |
+
|
| 64 |
+
if (substr(utf8_encode(pq($selector)->find('td:eq(0)')->html()),0,7)=="Nenhuma")
|
| 65 |
+
return null;
|
| 66 |
+
|
| 67 |
+
$ultimas_transacoes = array();
|
| 68 |
+
foreach(pq($selector) as $tr)
|
| 69 |
+
{
|
| 70 |
+
$tds = pq($tr);
|
| 71 |
+
|
| 72 |
+
$transacao = array('data'=>$tds->find('td:eq(0)')->html(),
|
| 73 |
+
'nome'=>$tds->find('td:eq(1)')->html(),
|
| 74 |
+
'pagamento'=>$tds->find('td:eq(2)')->html(),
|
| 75 |
+
'adicional'=>$tds->find('td:eq(3)')->html(),
|
| 76 |
+
'valor'=>$tds->find('td:eq(4)')->html()
|
| 77 |
+
);
|
| 78 |
+
$ultimas_transacoes[] = $transacao;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
return $ultimas_transacoes;
|
| 82 |
+
}
|
| 83 |
+
}
|
lib/Moip/phpQuery/phpQuery.php
ADDED
|
@@ -0,0 +1,5702 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* phpQuery is a server-side, chainable, CSS3 selector driven
|
| 4 |
+
* Document Object Model (DOM) API based on jQuery JavaScript Library.
|
| 5 |
+
*
|
| 6 |
+
* @version 0.9.5
|
| 7 |
+
* @link http://code.google.com/p/phpquery/
|
| 8 |
+
* @link http://phpquery-library.blogspot.com/
|
| 9 |
+
* @link http://jquery.com/
|
| 10 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 11 |
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
| 12 |
+
* @package phpQuery
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
// class names for instanceof
|
| 16 |
+
// TODO move them as class constants into phpQuery
|
| 17 |
+
define('DOMDOCUMENT', 'DOMDocument');
|
| 18 |
+
define('DOMELEMENT', 'DOMElement');
|
| 19 |
+
define('DOMNODELIST', 'DOMNodeList');
|
| 20 |
+
define('DOMNODE', 'DOMNode');
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* DOMEvent class.
|
| 24 |
+
*
|
| 25 |
+
* Based on
|
| 26 |
+
* @link http://developer.mozilla.org/En/DOM:event
|
| 27 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 28 |
+
* @package phpQuery
|
| 29 |
+
* @todo implement ArrayAccess ?
|
| 30 |
+
*/
|
| 31 |
+
class DOMEvent {
|
| 32 |
+
/**
|
| 33 |
+
* Returns a boolean indicating whether the event bubbles up through the DOM or not.
|
| 34 |
+
*
|
| 35 |
+
* @var unknown_type
|
| 36 |
+
*/
|
| 37 |
+
public $bubbles = true;
|
| 38 |
+
/**
|
| 39 |
+
* Returns a boolean indicating whether the event is cancelable.
|
| 40 |
+
*
|
| 41 |
+
* @var unknown_type
|
| 42 |
+
*/
|
| 43 |
+
public $cancelable = true;
|
| 44 |
+
/**
|
| 45 |
+
* Returns a reference to the currently registered target for the event.
|
| 46 |
+
*
|
| 47 |
+
* @var unknown_type
|
| 48 |
+
*/
|
| 49 |
+
public $currentTarget;
|
| 50 |
+
/**
|
| 51 |
+
* Returns detail about the event, depending on the type of event.
|
| 52 |
+
*
|
| 53 |
+
* @var unknown_type
|
| 54 |
+
* @link http://developer.mozilla.org/en/DOM/event.detail
|
| 55 |
+
*/
|
| 56 |
+
public $detail; // ???
|
| 57 |
+
/**
|
| 58 |
+
* Used to indicate which phase of the event flow is currently being evaluated.
|
| 59 |
+
*
|
| 60 |
+
* NOT IMPLEMENTED
|
| 61 |
+
*
|
| 62 |
+
* @var unknown_type
|
| 63 |
+
* @link http://developer.mozilla.org/en/DOM/event.eventPhase
|
| 64 |
+
*/
|
| 65 |
+
public $eventPhase; // ???
|
| 66 |
+
/**
|
| 67 |
+
* The explicit original target of the event (Mozilla-specific).
|
| 68 |
+
*
|
| 69 |
+
* NOT IMPLEMENTED
|
| 70 |
+
*
|
| 71 |
+
* @var unknown_type
|
| 72 |
+
*/
|
| 73 |
+
public $explicitOriginalTarget; // moz only
|
| 74 |
+
/**
|
| 75 |
+
* The original target of the event, before any retargetings (Mozilla-specific).
|
| 76 |
+
*
|
| 77 |
+
* NOT IMPLEMENTED
|
| 78 |
+
*
|
| 79 |
+
* @var unknown_type
|
| 80 |
+
*/
|
| 81 |
+
public $originalTarget; // moz only
|
| 82 |
+
/**
|
| 83 |
+
* Identifies a secondary target for the event.
|
| 84 |
+
*
|
| 85 |
+
* @var unknown_type
|
| 86 |
+
*/
|
| 87 |
+
public $relatedTarget;
|
| 88 |
+
/**
|
| 89 |
+
* Returns a reference to the target to which the event was originally dispatched.
|
| 90 |
+
*
|
| 91 |
+
* @var unknown_type
|
| 92 |
+
*/
|
| 93 |
+
public $target;
|
| 94 |
+
/**
|
| 95 |
+
* Returns the time that the event was created.
|
| 96 |
+
*
|
| 97 |
+
* @var unknown_type
|
| 98 |
+
*/
|
| 99 |
+
public $timeStamp;
|
| 100 |
+
/**
|
| 101 |
+
* Returns the name of the event (case-insensitive).
|
| 102 |
+
*/
|
| 103 |
+
public $type;
|
| 104 |
+
public $runDefault = true;
|
| 105 |
+
public $data = null;
|
| 106 |
+
public function __construct($data) {
|
| 107 |
+
foreach($data as $k => $v) {
|
| 108 |
+
$this->$k = $v;
|
| 109 |
+
}
|
| 110 |
+
if (! $this->timeStamp)
|
| 111 |
+
$this->timeStamp = time();
|
| 112 |
+
}
|
| 113 |
+
/**
|
| 114 |
+
* Cancels the event (if it is cancelable).
|
| 115 |
+
*
|
| 116 |
+
*/
|
| 117 |
+
public function preventDefault() {
|
| 118 |
+
$this->runDefault = false;
|
| 119 |
+
}
|
| 120 |
+
/**
|
| 121 |
+
* Stops the propagation of events further along in the DOM.
|
| 122 |
+
*
|
| 123 |
+
*/
|
| 124 |
+
public function stopPropagation() {
|
| 125 |
+
$this->bubbles = false;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* DOMDocumentWrapper class simplifies work with DOMDocument.
|
| 132 |
+
*
|
| 133 |
+
* Know bug:
|
| 134 |
+
* - in XHTML fragments, <br /> changes to <br clear="none" />
|
| 135 |
+
*
|
| 136 |
+
* @todo check XML catalogs compatibility
|
| 137 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 138 |
+
* @package phpQuery
|
| 139 |
+
*/
|
| 140 |
+
class DOMDocumentWrapper {
|
| 141 |
+
/**
|
| 142 |
+
* @var DOMDocument
|
| 143 |
+
*/
|
| 144 |
+
public $document;
|
| 145 |
+
public $id;
|
| 146 |
+
/**
|
| 147 |
+
* @todo Rewrite as method and quess if null.
|
| 148 |
+
* @var unknown_type
|
| 149 |
+
*/
|
| 150 |
+
public $contentType = '';
|
| 151 |
+
public $xpath;
|
| 152 |
+
public $uuid = 0;
|
| 153 |
+
public $data = array();
|
| 154 |
+
public $dataNodes = array();
|
| 155 |
+
public $events = array();
|
| 156 |
+
public $eventsNodes = array();
|
| 157 |
+
public $eventsGlobal = array();
|
| 158 |
+
/**
|
| 159 |
+
* @TODO iframes support http://code.google.com/p/phpquery/issues/detail?id=28
|
| 160 |
+
* @var unknown_type
|
| 161 |
+
*/
|
| 162 |
+
public $frames = array();
|
| 163 |
+
/**
|
| 164 |
+
* Document root, by default equals to document itself.
|
| 165 |
+
* Used by documentFragments.
|
| 166 |
+
*
|
| 167 |
+
* @var DOMNode
|
| 168 |
+
*/
|
| 169 |
+
public $root;
|
| 170 |
+
public $isDocumentFragment;
|
| 171 |
+
public $isXML = false;
|
| 172 |
+
public $isXHTML = false;
|
| 173 |
+
public $isHTML = false;
|
| 174 |
+
public $charset;
|
| 175 |
+
public function __construct($markup = null, $contentType = null, $newDocumentID = null) {
|
| 176 |
+
if (isset($markup))
|
| 177 |
+
$this->load($markup, $contentType, $newDocumentID);
|
| 178 |
+
$this->id = $newDocumentID
|
| 179 |
+
? $newDocumentID
|
| 180 |
+
: md5(microtime());
|
| 181 |
+
}
|
| 182 |
+
public function load($markup, $contentType = null, $newDocumentID = null) {
|
| 183 |
+
// phpQuery::$documents[$id] = $this;
|
| 184 |
+
$this->contentType = strtolower($contentType);
|
| 185 |
+
if ($markup instanceof DOMDOCUMENT) {
|
| 186 |
+
$this->document = $markup;
|
| 187 |
+
$this->root = $this->document;
|
| 188 |
+
$this->charset = $this->document->encoding;
|
| 189 |
+
// TODO isDocumentFragment
|
| 190 |
+
} else {
|
| 191 |
+
$loaded = $this->loadMarkup($markup);
|
| 192 |
+
}
|
| 193 |
+
if ($loaded) {
|
| 194 |
+
// $this->document->formatOutput = true;
|
| 195 |
+
$this->document->preserveWhiteSpace = true;
|
| 196 |
+
$this->xpath = new DOMXPath($this->document);
|
| 197 |
+
$this->afterMarkupLoad();
|
| 198 |
+
return true;
|
| 199 |
+
// remember last loaded document
|
| 200 |
+
// return phpQuery::selectDocument($id);
|
| 201 |
+
}
|
| 202 |
+
return false;
|
| 203 |
+
}
|
| 204 |
+
protected function afterMarkupLoad() {
|
| 205 |
+
if ($this->isXHTML) {
|
| 206 |
+
$this->xpath->registerNamespace("html", "http://www.w3.org/1999/xhtml");
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
protected function loadMarkup($markup) {
|
| 210 |
+
$loaded = false;
|
| 211 |
+
if ($this->contentType) {
|
| 212 |
+
self::debug("Load markup for content type {$this->contentType}");
|
| 213 |
+
// content determined by contentType
|
| 214 |
+
list($contentType, $charset) = $this->contentTypeToArray($this->contentType);
|
| 215 |
+
switch($contentType) {
|
| 216 |
+
case 'text/html':
|
| 217 |
+
phpQuery::debug("Loading HTML, content type '{$this->contentType}'");
|
| 218 |
+
$loaded = $this->loadMarkupHTML($markup, $charset);
|
| 219 |
+
break;
|
| 220 |
+
case 'text/xml':
|
| 221 |
+
case 'application/xhtml+xml':
|
| 222 |
+
phpQuery::debug("Loading XML, content type '{$this->contentType}'");
|
| 223 |
+
$loaded = $this->loadMarkupXML($markup, $charset);
|
| 224 |
+
break;
|
| 225 |
+
default:
|
| 226 |
+
// for feeds or anything that sometimes doesn't use text/xml
|
| 227 |
+
if (strpos('xml', $this->contentType) !== false) {
|
| 228 |
+
phpQuery::debug("Loading XML, content type '{$this->contentType}'");
|
| 229 |
+
$loaded = $this->loadMarkupXML($markup, $charset);
|
| 230 |
+
} else
|
| 231 |
+
phpQuery::debug("Could not determine document type from content type '{$this->contentType}'");
|
| 232 |
+
}
|
| 233 |
+
} else {
|
| 234 |
+
// content type autodetection
|
| 235 |
+
if ($this->isXML($markup)) {
|
| 236 |
+
phpQuery::debug("Loading XML, isXML() == true");
|
| 237 |
+
$loaded = $this->loadMarkupXML($markup);
|
| 238 |
+
if (! $loaded && $this->isXHTML) {
|
| 239 |
+
phpQuery::debug('Loading as XML failed, trying to load as HTML, isXHTML == true');
|
| 240 |
+
$loaded = $this->loadMarkupHTML($markup);
|
| 241 |
+
}
|
| 242 |
+
} else {
|
| 243 |
+
phpQuery::debug("Loading HTML, isXML() == false");
|
| 244 |
+
$loaded = $this->loadMarkupHTML($markup);
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
return $loaded;
|
| 248 |
+
}
|
| 249 |
+
protected function loadMarkupReset() {
|
| 250 |
+
$this->isXML = $this->isXHTML = $this->isHTML = false;
|
| 251 |
+
}
|
| 252 |
+
protected function documentCreate($charset, $version = '1.0') {
|
| 253 |
+
if (! $version)
|
| 254 |
+
$version = '1.0';
|
| 255 |
+
$this->document = new DOMDocument($version, $charset);
|
| 256 |
+
$this->charset = $this->document->encoding;
|
| 257 |
+
// $this->document->encoding = $charset;
|
| 258 |
+
$this->document->formatOutput = true;
|
| 259 |
+
$this->document->preserveWhiteSpace = true;
|
| 260 |
+
}
|
| 261 |
+
protected function loadMarkupHTML($markup, $requestedCharset = null) {
|
| 262 |
+
if (phpQuery::$debug)
|
| 263 |
+
phpQuery::debug('Full markup load (HTML): '.substr($markup, 0, 250));
|
| 264 |
+
$this->loadMarkupReset();
|
| 265 |
+
$this->isHTML = true;
|
| 266 |
+
if (!isset($this->isDocumentFragment))
|
| 267 |
+
$this->isDocumentFragment = self::isDocumentFragmentHTML($markup);
|
| 268 |
+
$charset = null;
|
| 269 |
+
$documentCharset = $this->charsetFromHTML($markup);
|
| 270 |
+
$addDocumentCharset = false;
|
| 271 |
+
if ($documentCharset) {
|
| 272 |
+
$charset = $documentCharset;
|
| 273 |
+
$markup = $this->charsetFixHTML($markup);
|
| 274 |
+
} else if ($requestedCharset) {
|
| 275 |
+
$charset = $requestedCharset;
|
| 276 |
+
}
|
| 277 |
+
if (! $charset)
|
| 278 |
+
$charset = phpQuery::$defaultCharset;
|
| 279 |
+
// HTTP 1.1 says that the default charset is ISO-8859-1
|
| 280 |
+
// @see http://www.w3.org/International/O-HTTP-charset
|
| 281 |
+
if (! $documentCharset) {
|
| 282 |
+
$documentCharset = 'ISO-8859-1';
|
| 283 |
+
$addDocumentCharset = true;
|
| 284 |
+
}
|
| 285 |
+
// Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding'
|
| 286 |
+
// Worse, some pages can have mixed encodings... we'll try not to worry about that
|
| 287 |
+
$requestedCharset = strtoupper($requestedCharset);
|
| 288 |
+
$documentCharset = strtoupper($documentCharset);
|
| 289 |
+
phpQuery::debug("DOC: $documentCharset REQ: $requestedCharset");
|
| 290 |
+
if ($requestedCharset && $documentCharset && $requestedCharset !== $documentCharset) {
|
| 291 |
+
phpQuery::debug("CHARSET CONVERT");
|
| 292 |
+
// Document Encoding Conversion
|
| 293 |
+
// http://code.google.com/p/phpquery/issues/detail?id=86
|
| 294 |
+
if (function_exists('mb_detect_encoding')) {
|
| 295 |
+
$possibleCharsets = array($documentCharset, $requestedCharset, 'AUTO');
|
| 296 |
+
$docEncoding = mb_detect_encoding($markup, implode(', ', $possibleCharsets));
|
| 297 |
+
if (! $docEncoding)
|
| 298 |
+
$docEncoding = $documentCharset; // ok trust the document
|
| 299 |
+
phpQuery::debug("DETECTED '$docEncoding'");
|
| 300 |
+
// Detected does not match what document says...
|
| 301 |
+
if ($docEncoding !== $documentCharset) {
|
| 302 |
+
// Tricky..
|
| 303 |
+
}
|
| 304 |
+
if ($docEncoding !== $requestedCharset) {
|
| 305 |
+
phpQuery::debug("CONVERT $docEncoding => $requestedCharset");
|
| 306 |
+
$markup = mb_convert_encoding($markup, $requestedCharset, $docEncoding);
|
| 307 |
+
$markup = $this->charsetAppendToHTML($markup, $requestedCharset);
|
| 308 |
+
$charset = $requestedCharset;
|
| 309 |
+
}
|
| 310 |
+
} else {
|
| 311 |
+
phpQuery::debug("TODO: charset conversion without mbstring...");
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
$return = false;
|
| 315 |
+
if ($this->isDocumentFragment) {
|
| 316 |
+
phpQuery::debug("Full markup load (HTML), DocumentFragment detected, using charset '$charset'");
|
| 317 |
+
$return = $this->documentFragmentLoadMarkup($this, $charset, $markup);
|
| 318 |
+
} else {
|
| 319 |
+
if ($addDocumentCharset) {
|
| 320 |
+
phpQuery::debug("Full markup load (HTML), appending charset: '$charset'");
|
| 321 |
+
$markup = $this->charsetAppendToHTML($markup, $charset);
|
| 322 |
+
}
|
| 323 |
+
phpQuery::debug("Full markup load (HTML), documentCreate('$charset')");
|
| 324 |
+
$this->documentCreate($charset);
|
| 325 |
+
$return = phpQuery::$debug === 2
|
| 326 |
+
? $this->document->loadHTML($markup)
|
| 327 |
+
: @$this->document->loadHTML($markup);
|
| 328 |
+
if ($return)
|
| 329 |
+
$this->root = $this->document;
|
| 330 |
+
}
|
| 331 |
+
if ($return && ! $this->contentType)
|
| 332 |
+
$this->contentType = 'text/html';
|
| 333 |
+
return $return;
|
| 334 |
+
}
|
| 335 |
+
protected function loadMarkupXML($markup, $requestedCharset = null) {
|
| 336 |
+
if (phpQuery::$debug)
|
| 337 |
+
phpQuery::debug('Full markup load (XML): '.substr($markup, 0, 250));
|
| 338 |
+
$this->loadMarkupReset();
|
| 339 |
+
$this->isXML = true;
|
| 340 |
+
// check agains XHTML in contentType or markup
|
| 341 |
+
$isContentTypeXHTML = $this->isXHTML();
|
| 342 |
+
$isMarkupXHTML = $this->isXHTML($markup);
|
| 343 |
+
if ($isContentTypeXHTML || $isMarkupXHTML) {
|
| 344 |
+
self::debug('Full markup load (XML), XHTML detected');
|
| 345 |
+
$this->isXHTML = true;
|
| 346 |
+
}
|
| 347 |
+
// determine document fragment
|
| 348 |
+
if (! isset($this->isDocumentFragment))
|
| 349 |
+
$this->isDocumentFragment = $this->isXHTML
|
| 350 |
+
? self::isDocumentFragmentXHTML($markup)
|
| 351 |
+
: self::isDocumentFragmentXML($markup);
|
| 352 |
+
// this charset will be used
|
| 353 |
+
$charset = null;
|
| 354 |
+
// charset from XML declaration @var string
|
| 355 |
+
$documentCharset = $this->charsetFromXML($markup);
|
| 356 |
+
if (! $documentCharset) {
|
| 357 |
+
if ($this->isXHTML) {
|
| 358 |
+
// this is XHTML, try to get charset from content-type meta header
|
| 359 |
+
$documentCharset = $this->charsetFromHTML($markup);
|
| 360 |
+
if ($documentCharset) {
|
| 361 |
+
phpQuery::debug("Full markup load (XML), appending XHTML charset '$documentCharset'");
|
| 362 |
+
$this->charsetAppendToXML($markup, $documentCharset);
|
| 363 |
+
$charset = $documentCharset;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
if (! $documentCharset) {
|
| 367 |
+
// if still no document charset...
|
| 368 |
+
$charset = $requestedCharset;
|
| 369 |
+
}
|
| 370 |
+
} else if ($requestedCharset) {
|
| 371 |
+
$charset = $requestedCharset;
|
| 372 |
+
}
|
| 373 |
+
if (! $charset) {
|
| 374 |
+
$charset = phpQuery::$defaultCharset;
|
| 375 |
+
}
|
| 376 |
+
if ($requestedCharset && $documentCharset && $requestedCharset != $documentCharset) {
|
| 377 |
+
// TODO place for charset conversion
|
| 378 |
+
// $charset = $requestedCharset;
|
| 379 |
+
}
|
| 380 |
+
$return = false;
|
| 381 |
+
if ($this->isDocumentFragment) {
|
| 382 |
+
phpQuery::debug("Full markup load (XML), DocumentFragment detected, using charset '$charset'");
|
| 383 |
+
$return = $this->documentFragmentLoadMarkup($this, $charset, $markup);
|
| 384 |
+
} else {
|
| 385 |
+
// FIXME ???
|
| 386 |
+
if ($isContentTypeXHTML && ! $isMarkupXHTML)
|
| 387 |
+
if (! $documentCharset) {
|
| 388 |
+
phpQuery::debug("Full markup load (XML), appending charset '$charset'");
|
| 389 |
+
$markup = $this->charsetAppendToXML($markup, $charset);
|
| 390 |
+
}
|
| 391 |
+
// see http://pl2.php.net/manual/en/book.dom.php#78929
|
| 392 |
+
// LIBXML_DTDLOAD (>= PHP 5.1)
|
| 393 |
+
// does XML ctalogues works with LIBXML_NONET
|
| 394 |
+
// $this->document->resolveExternals = true;
|
| 395 |
+
// TODO test LIBXML_COMPACT for performance improvement
|
| 396 |
+
// create document
|
| 397 |
+
$this->documentCreate($charset);
|
| 398 |
+
if (phpversion() < 5.1) {
|
| 399 |
+
$this->document->resolveExternals = true;
|
| 400 |
+
$return = phpQuery::$debug === 2
|
| 401 |
+
? $this->document->loadXML($markup)
|
| 402 |
+
: @$this->document->loadXML($markup);
|
| 403 |
+
} else {
|
| 404 |
+
/** @link http://pl2.php.net/manual/en/libxml.constants.php */
|
| 405 |
+
$libxmlStatic = phpQuery::$debug === 2
|
| 406 |
+
? LIBXML_DTDLOAD|LIBXML_DTDATTR|LIBXML_NONET
|
| 407 |
+
: LIBXML_DTDLOAD|LIBXML_DTDATTR|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOERROR;
|
| 408 |
+
$return = $this->document->loadXML($markup, $libxmlStatic);
|
| 409 |
+
// if (! $return)
|
| 410 |
+
// $return = $this->document->loadHTML($markup);
|
| 411 |
+
}
|
| 412 |
+
if ($return)
|
| 413 |
+
$this->root = $this->document;
|
| 414 |
+
}
|
| 415 |
+
if ($return) {
|
| 416 |
+
if (! $this->contentType) {
|
| 417 |
+
if ($this->isXHTML)
|
| 418 |
+
$this->contentType = 'application/xhtml+xml';
|
| 419 |
+
else
|
| 420 |
+
$this->contentType = 'text/xml';
|
| 421 |
+
}
|
| 422 |
+
return $return;
|
| 423 |
+
} else {
|
| 424 |
+
throw new Exception("Error loading XML markup");
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
protected function isXHTML($markup = null) {
|
| 428 |
+
if (! isset($markup)) {
|
| 429 |
+
return strpos($this->contentType, 'xhtml') !== false;
|
| 430 |
+
}
|
| 431 |
+
// XXX ok ?
|
| 432 |
+
return strpos($markup, "<!DOCTYPE html") !== false;
|
| 433 |
+
// return stripos($doctype, 'xhtml') !== false;
|
| 434 |
+
// $doctype = isset($dom->doctype) && is_object($dom->doctype)
|
| 435 |
+
// ? $dom->doctype->publicId
|
| 436 |
+
// : self::$defaultDoctype;
|
| 437 |
+
}
|
| 438 |
+
protected function isXML($markup) {
|
| 439 |
+
// return strpos($markup, '<?xml') !== false && stripos($markup, 'xhtml') === false;
|
| 440 |
+
return strpos(substr($markup, 0, 100), '<'.'?xml') !== false;
|
| 441 |
+
}
|
| 442 |
+
protected function contentTypeToArray($contentType) {
|
| 443 |
+
$matches = explode(';', trim(strtolower($contentType)));
|
| 444 |
+
if (isset($matches[1])) {
|
| 445 |
+
$matches[1] = explode('=', $matches[1]);
|
| 446 |
+
// strip 'charset='
|
| 447 |
+
$matches[1] = isset($matches[1][1]) && trim($matches[1][1])
|
| 448 |
+
? $matches[1][1]
|
| 449 |
+
: $matches[1][0];
|
| 450 |
+
} else
|
| 451 |
+
$matches[1] = null;
|
| 452 |
+
return $matches;
|
| 453 |
+
}
|
| 454 |
+
/**
|
| 455 |
+
*
|
| 456 |
+
* @param $markup
|
| 457 |
+
* @return array contentType, charset
|
| 458 |
+
*/
|
| 459 |
+
protected function contentTypeFromHTML($markup) {
|
| 460 |
+
$matches = array();
|
| 461 |
+
// find meta tag
|
| 462 |
+
preg_match('@<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i',
|
| 463 |
+
$markup, $matches
|
| 464 |
+
);
|
| 465 |
+
if (! isset($matches[0]))
|
| 466 |
+
return array(null, null);
|
| 467 |
+
// get attr 'content'
|
| 468 |
+
preg_match('@content\\s*=\\s*(["|\'])(.+?)\\1@', $matches[0], $matches);
|
| 469 |
+
if (! isset($matches[0]))
|
| 470 |
+
return array(null, null);
|
| 471 |
+
return $this->contentTypeToArray($matches[2]);
|
| 472 |
+
}
|
| 473 |
+
protected function charsetFromHTML($markup) {
|
| 474 |
+
$contentType = $this->contentTypeFromHTML($markup);
|
| 475 |
+
return $contentType[1];
|
| 476 |
+
}
|
| 477 |
+
protected function charsetFromXML($markup) {
|
| 478 |
+
$matches;
|
| 479 |
+
// find declaration
|
| 480 |
+
preg_match('@<'.'?xml[^>]+encoding\\s*=\\s*(["|\'])(.*?)\\1@i',
|
| 481 |
+
$markup, $matches
|
| 482 |
+
);
|
| 483 |
+
return isset($matches[2])
|
| 484 |
+
? strtolower($matches[2])
|
| 485 |
+
: null;
|
| 486 |
+
}
|
| 487 |
+
/**
|
| 488 |
+
* Repositions meta[type=charset] at the start of head. Bypasses DOMDocument bug.
|
| 489 |
+
*
|
| 490 |
+
* @link http://code.google.com/p/phpquery/issues/detail?id=80
|
| 491 |
+
* @param $html
|
| 492 |
+
*/
|
| 493 |
+
protected function charsetFixHTML($markup) {
|
| 494 |
+
$matches = array();
|
| 495 |
+
// find meta tag
|
| 496 |
+
preg_match('@\s*<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i',
|
| 497 |
+
$markup, $matches, PREG_OFFSET_CAPTURE
|
| 498 |
+
);
|
| 499 |
+
if (! isset($matches[0]))
|
| 500 |
+
return;
|
| 501 |
+
$metaContentType = $matches[0][0];
|
| 502 |
+
$markup = substr($markup, 0, $matches[0][1])
|
| 503 |
+
.substr($markup, $matches[0][1]+strlen($metaContentType));
|
| 504 |
+
$headStart = stripos($markup, '<head>');
|
| 505 |
+
$markup = substr($markup, 0, $headStart+6).$metaContentType
|
| 506 |
+
.substr($markup, $headStart+6);
|
| 507 |
+
return $markup;
|
| 508 |
+
}
|
| 509 |
+
protected function charsetAppendToHTML($html, $charset, $xhtml = false) {
|
| 510 |
+
// remove existing meta[type=content-type]
|
| 511 |
+
$html = preg_replace('@\s*<meta[^>]+http-equiv\\s*=\\s*(["|\'])Content-Type\\1([^>]+?)>@i', '', $html);
|
| 512 |
+
$meta = '<meta http-equiv="Content-Type" content="text/html;charset='
|
| 513 |
+
.$charset.'" '
|
| 514 |
+
.($xhtml ? '/' : '')
|
| 515 |
+
.'>';
|
| 516 |
+
if (strpos($html, '<head') === false) {
|
| 517 |
+
if (strpos($hltml, '<html') === false) {
|
| 518 |
+
return $meta.$html;
|
| 519 |
+
} else {
|
| 520 |
+
return preg_replace(
|
| 521 |
+
'@<html(.*?)(?(?<!\?)>)@s',
|
| 522 |
+
"<html\\1><head>{$meta}</head>",
|
| 523 |
+
$html
|
| 524 |
+
);
|
| 525 |
+
}
|
| 526 |
+
} else {
|
| 527 |
+
return preg_replace(
|
| 528 |
+
'@<head(.*?)(?(?<!\?)>)@s',
|
| 529 |
+
'<head\\1>'.$meta,
|
| 530 |
+
$html
|
| 531 |
+
);
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
protected function charsetAppendToXML($markup, $charset) {
|
| 535 |
+
$declaration = '<'.'?xml version="1.0" encoding="'.$charset.'"?'.'>';
|
| 536 |
+
return $declaration.$markup;
|
| 537 |
+
}
|
| 538 |
+
public static function isDocumentFragmentHTML($markup) {
|
| 539 |
+
return stripos($markup, '<html') === false && stripos($markup, '<!doctype') === false;
|
| 540 |
+
}
|
| 541 |
+
public static function isDocumentFragmentXML($markup) {
|
| 542 |
+
return stripos($markup, '<'.'?xml') === false;
|
| 543 |
+
}
|
| 544 |
+
public static function isDocumentFragmentXHTML($markup) {
|
| 545 |
+
return self::isDocumentFragmentHTML($markup);
|
| 546 |
+
}
|
| 547 |
+
public function importAttr($value) {
|
| 548 |
+
// TODO
|
| 549 |
+
}
|
| 550 |
+
/**
|
| 551 |
+
*
|
| 552 |
+
* @param $source
|
| 553 |
+
* @param $target
|
| 554 |
+
* @param $sourceCharset
|
| 555 |
+
* @return array Array of imported nodes.
|
| 556 |
+
*/
|
| 557 |
+
public function import($source, $sourceCharset = null) {
|
| 558 |
+
// TODO charset conversions
|
| 559 |
+
$return = array();
|
| 560 |
+
if ($source instanceof DOMNODE && !($source instanceof DOMNODELIST))
|
| 561 |
+
$source = array($source);
|
| 562 |
+
// if (is_array($source)) {
|
| 563 |
+
// foreach($source as $node) {
|
| 564 |
+
// if (is_string($node)) {
|
| 565 |
+
// // string markup
|
| 566 |
+
// $fake = $this->documentFragmentCreate($node, $sourceCharset);
|
| 567 |
+
// if ($fake === false)
|
| 568 |
+
// throw new Exception("Error loading documentFragment markup");
|
| 569 |
+
// else
|
| 570 |
+
// $return = array_merge($return,
|
| 571 |
+
// $this->import($fake->root->childNodes)
|
| 572 |
+
// );
|
| 573 |
+
// } else {
|
| 574 |
+
// $return[] = $this->document->importNode($node, true);
|
| 575 |
+
// }
|
| 576 |
+
// }
|
| 577 |
+
// return $return;
|
| 578 |
+
// } else {
|
| 579 |
+
// // string markup
|
| 580 |
+
// $fake = $this->documentFragmentCreate($source, $sourceCharset);
|
| 581 |
+
// if ($fake === false)
|
| 582 |
+
// throw new Exception("Error loading documentFragment markup");
|
| 583 |
+
// else
|
| 584 |
+
// return $this->import($fake->root->childNodes);
|
| 585 |
+
// }
|
| 586 |
+
if (is_array($source) || $source instanceof DOMNODELIST) {
|
| 587 |
+
// dom nodes
|
| 588 |
+
self::debug('Importing nodes to document');
|
| 589 |
+
foreach($source as $node)
|
| 590 |
+
$return[] = $this->document->importNode($node, true);
|
| 591 |
+
} else {
|
| 592 |
+
// string markup
|
| 593 |
+
$fake = $this->documentFragmentCreate($source, $sourceCharset);
|
| 594 |
+
if ($fake === false)
|
| 595 |
+
throw new Exception("Error loading documentFragment markup");
|
| 596 |
+
else
|
| 597 |
+
return $this->import($fake->root->childNodes);
|
| 598 |
+
}
|
| 599 |
+
return $return;
|
| 600 |
+
}
|
| 601 |
+
/**
|
| 602 |
+
* Creates new document fragment.
|
| 603 |
+
*
|
| 604 |
+
* @param $source
|
| 605 |
+
* @return DOMDocumentWrapper
|
| 606 |
+
*/
|
| 607 |
+
protected function documentFragmentCreate($source, $charset = null) {
|
| 608 |
+
$fake = new DOMDocumentWrapper();
|
| 609 |
+
$fake->contentType = $this->contentType;
|
| 610 |
+
$fake->isXML = $this->isXML;
|
| 611 |
+
$fake->isHTML = $this->isHTML;
|
| 612 |
+
$fake->isXHTML = $this->isXHTML;
|
| 613 |
+
$fake->root = $fake->document;
|
| 614 |
+
if (! $charset)
|
| 615 |
+
$charset = $this->charset;
|
| 616 |
+
// $fake->documentCreate($this->charset);
|
| 617 |
+
if ($source instanceof DOMNODE && !($source instanceof DOMNODELIST))
|
| 618 |
+
$source = array($source);
|
| 619 |
+
if (is_array($source) || $source instanceof DOMNODELIST) {
|
| 620 |
+
// dom nodes
|
| 621 |
+
// load fake document
|
| 622 |
+
if (! $this->documentFragmentLoadMarkup($fake, $charset))
|
| 623 |
+
return false;
|
| 624 |
+
$nodes = $fake->import($source);
|
| 625 |
+
foreach($nodes as $node)
|
| 626 |
+
$fake->root->appendChild($node);
|
| 627 |
+
} else {
|
| 628 |
+
// string markup
|
| 629 |
+
$this->documentFragmentLoadMarkup($fake, $charset, $source);
|
| 630 |
+
}
|
| 631 |
+
return $fake;
|
| 632 |
+
}
|
| 633 |
+
/**
|
| 634 |
+
*
|
| 635 |
+
* @param $document DOMDocumentWrapper
|
| 636 |
+
* @param $markup
|
| 637 |
+
* @return $document
|
| 638 |
+
*/
|
| 639 |
+
private function documentFragmentLoadMarkup($fragment, $charset, $markup = null) {
|
| 640 |
+
// TODO error handling
|
| 641 |
+
// TODO copy doctype
|
| 642 |
+
// tempolary turn off
|
| 643 |
+
$fragment->isDocumentFragment = false;
|
| 644 |
+
if ($fragment->isXML) {
|
| 645 |
+
if ($fragment->isXHTML) {
|
| 646 |
+
// add FAKE element to set default namespace
|
| 647 |
+
$fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?>'
|
| 648 |
+
.'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
|
| 649 |
+
.'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
|
| 650 |
+
.'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');
|
| 651 |
+
$fragment->root = $fragment->document->firstChild->nextSibling;
|
| 652 |
+
} else {
|
| 653 |
+
$fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?><fake>'.$markup.'</fake>');
|
| 654 |
+
$fragment->root = $fragment->document->firstChild;
|
| 655 |
+
}
|
| 656 |
+
} else {
|
| 657 |
+
$markup2 = phpQuery::$defaultDoctype.'<html><head><meta http-equiv="Content-Type" content="text/html;charset='
|
| 658 |
+
.$charset.'"></head>';
|
| 659 |
+
$noBody = strpos($markup, '<body') === false;
|
| 660 |
+
if ($noBody)
|
| 661 |
+
$markup2 .= '<body>';
|
| 662 |
+
$markup2 .= $markup;
|
| 663 |
+
if ($noBody)
|
| 664 |
+
$markup2 .= '</body>';
|
| 665 |
+
$markup2 .= '</html>';
|
| 666 |
+
$fragment->loadMarkupHTML($markup2);
|
| 667 |
+
// TODO resolv body tag merging issue
|
| 668 |
+
$fragment->root = $noBody
|
| 669 |
+
? $fragment->document->firstChild->nextSibling->firstChild->nextSibling
|
| 670 |
+
: $fragment->document->firstChild->nextSibling->firstChild->nextSibling;
|
| 671 |
+
}
|
| 672 |
+
if (! $fragment->root)
|
| 673 |
+
return false;
|
| 674 |
+
$fragment->isDocumentFragment = true;
|
| 675 |
+
return true;
|
| 676 |
+
}
|
| 677 |
+
protected function documentFragmentToMarkup($fragment) {
|
| 678 |
+
phpQuery::debug('documentFragmentToMarkup');
|
| 679 |
+
$tmp = $fragment->isDocumentFragment;
|
| 680 |
+
$fragment->isDocumentFragment = false;
|
| 681 |
+
$markup = $fragment->markup();
|
| 682 |
+
if ($fragment->isXML) {
|
| 683 |
+
$markup = substr($markup, 0, strrpos($markup, '</fake>'));
|
| 684 |
+
if ($fragment->isXHTML) {
|
| 685 |
+
$markup = substr($markup, strpos($markup, '<fake')+43);
|
| 686 |
+
} else {
|
| 687 |
+
$markup = substr($markup, strpos($markup, '<fake>')+6);
|
| 688 |
+
}
|
| 689 |
+
} else {
|
| 690 |
+
$markup = substr($markup, strpos($markup, '<body>')+6);
|
| 691 |
+
$markup = substr($markup, 0, strrpos($markup, '</body>'));
|
| 692 |
+
}
|
| 693 |
+
$fragment->isDocumentFragment = $tmp;
|
| 694 |
+
if (phpQuery::$debug)
|
| 695 |
+
phpQuery::debug('documentFragmentToMarkup: '.substr($markup, 0, 150));
|
| 696 |
+
return $markup;
|
| 697 |
+
}
|
| 698 |
+
/**
|
| 699 |
+
* Return document markup, starting with optional $nodes as root.
|
| 700 |
+
*
|
| 701 |
+
* @param $nodes DOMNode|DOMNodeList
|
| 702 |
+
* @return string
|
| 703 |
+
*/
|
| 704 |
+
public function markup($nodes = null, $innerMarkup = false) {
|
| 705 |
+
if (isset($nodes) && count($nodes) == 1 && $nodes[0] instanceof DOMDOCUMENT)
|
| 706 |
+
$nodes = null;
|
| 707 |
+
if (isset($nodes)) {
|
| 708 |
+
$markup = '';
|
| 709 |
+
if (!is_array($nodes) && !($nodes instanceof DOMNODELIST) )
|
| 710 |
+
$nodes = array($nodes);
|
| 711 |
+
if ($this->isDocumentFragment && ! $innerMarkup)
|
| 712 |
+
foreach($nodes as $i => $node)
|
| 713 |
+
if ($node->isSameNode($this->root)) {
|
| 714 |
+
// var_dump($node);
|
| 715 |
+
$nodes = array_slice($nodes, 0, $i)
|
| 716 |
+
+ phpQuery::DOMNodeListToArray($node->childNodes)
|
| 717 |
+
+ array_slice($nodes, $i+1);
|
| 718 |
+
}
|
| 719 |
+
if ($this->isXML && ! $innerMarkup) {
|
| 720 |
+
self::debug("Getting outerXML with charset '{$this->charset}'");
|
| 721 |
+
// we need outerXML, so we can benefit from
|
| 722 |
+
// $node param support in saveXML()
|
| 723 |
+
foreach($nodes as $node)
|
| 724 |
+
$markup .= $this->document->saveXML($node);
|
| 725 |
+
} else {
|
| 726 |
+
$loop = array();
|
| 727 |
+
if ($innerMarkup)
|
| 728 |
+
foreach($nodes as $node) {
|
| 729 |
+
if ($node->childNodes)
|
| 730 |
+
foreach($node->childNodes as $child)
|
| 731 |
+
$loop[] = $child;
|
| 732 |
+
else
|
| 733 |
+
$loop[] = $node;
|
| 734 |
+
}
|
| 735 |
+
else
|
| 736 |
+
$loop = $nodes;
|
| 737 |
+
self::debug("Getting markup, moving selected nodes (".count($loop).") to new DocumentFragment");
|
| 738 |
+
$fake = $this->documentFragmentCreate($loop);
|
| 739 |
+
$markup = $this->documentFragmentToMarkup($fake);
|
| 740 |
+
}
|
| 741 |
+
if ($this->isXHTML) {
|
| 742 |
+
self::debug("Fixing XHTML");
|
| 743 |
+
$markup = self::markupFixXHTML($markup);
|
| 744 |
+
}
|
| 745 |
+
self::debug("Markup: ".substr($markup, 0, 250));
|
| 746 |
+
return $markup;
|
| 747 |
+
} else {
|
| 748 |
+
if ($this->isDocumentFragment) {
|
| 749 |
+
// documentFragment, html only...
|
| 750 |
+
self::debug("Getting markup, DocumentFragment detected");
|
| 751 |
+
// return $this->markup(
|
| 752 |
+
//// $this->document->getElementsByTagName('body')->item(0)
|
| 753 |
+
// $this->document->root, true
|
| 754 |
+
// );
|
| 755 |
+
$markup = $this->documentFragmentToMarkup($this);
|
| 756 |
+
// no need for markupFixXHTML, as it's done thought markup($nodes) method
|
| 757 |
+
return $markup;
|
| 758 |
+
} else {
|
| 759 |
+
self::debug("Getting markup (".($this->isXML?'XML':'HTML')."), final with charset '{$this->charset}'");
|
| 760 |
+
$markup = $this->isXML
|
| 761 |
+
? $this->document->saveXML()
|
| 762 |
+
: $this->document->saveHTML();
|
| 763 |
+
if ($this->isXHTML) {
|
| 764 |
+
self::debug("Fixing XHTML");
|
| 765 |
+
$markup = self::markupFixXHTML($markup);
|
| 766 |
+
}
|
| 767 |
+
self::debug("Markup: ".substr($markup, 0, 250));
|
| 768 |
+
return $markup;
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
+
}
|
| 772 |
+
protected static function markupFixXHTML($markup) {
|
| 773 |
+
$markup = self::expandEmptyTag('script', $markup);
|
| 774 |
+
$markup = self::expandEmptyTag('select', $markup);
|
| 775 |
+
$markup = self::expandEmptyTag('textarea', $markup);
|
| 776 |
+
return $markup;
|
| 777 |
+
}
|
| 778 |
+
public static function debug($text) {
|
| 779 |
+
phpQuery::debug($text);
|
| 780 |
+
}
|
| 781 |
+
/**
|
| 782 |
+
* expandEmptyTag
|
| 783 |
+
*
|
| 784 |
+
* @param $tag
|
| 785 |
+
* @param $xml
|
| 786 |
+
* @return unknown_type
|
| 787 |
+
* @author mjaque at ilkebenson dot com
|
| 788 |
+
* @link http://php.net/manual/en/domdocument.savehtml.php#81256
|
| 789 |
+
*/
|
| 790 |
+
public static function expandEmptyTag($tag, $xml){
|
| 791 |
+
$indice = 0;
|
| 792 |
+
while ($indice< strlen($xml)){
|
| 793 |
+
$pos = strpos($xml, "<$tag ", $indice);
|
| 794 |
+
if ($pos){
|
| 795 |
+
$posCierre = strpos($xml, ">", $pos);
|
| 796 |
+
if ($xml[$posCierre-1] == "/"){
|
| 797 |
+
$xml = substr_replace($xml, "></$tag>", $posCierre-1, 2);
|
| 798 |
+
}
|
| 799 |
+
$indice = $posCierre;
|
| 800 |
+
}
|
| 801 |
+
else break;
|
| 802 |
+
}
|
| 803 |
+
return $xml;
|
| 804 |
+
}
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
/**
|
| 808 |
+
* Event handling class.
|
| 809 |
+
*
|
| 810 |
+
* @author Tobiasz Cudnik
|
| 811 |
+
* @package phpQuery
|
| 812 |
+
* @static
|
| 813 |
+
*/
|
| 814 |
+
abstract class phpQueryEvents {
|
| 815 |
+
/**
|
| 816 |
+
* Trigger a type of event on every matched element.
|
| 817 |
+
*
|
| 818 |
+
* @param DOMNode|phpQueryObject|string $document
|
| 819 |
+
* @param unknown_type $type
|
| 820 |
+
* @param unknown_type $data
|
| 821 |
+
*
|
| 822 |
+
* @TODO exclusive events (with !)
|
| 823 |
+
* @TODO global events (test)
|
| 824 |
+
* @TODO support more than event in $type (space-separated)
|
| 825 |
+
*/
|
| 826 |
+
public static function trigger($document, $type, $data = array(), $node = null) {
|
| 827 |
+
// trigger: function(type, data, elem, donative, extra) {
|
| 828 |
+
$documentID = phpQuery::getDocumentID($document);
|
| 829 |
+
$namespace = null;
|
| 830 |
+
if (strpos($type, '.') !== false)
|
| 831 |
+
list($name, $namespace) = explode('.', $type);
|
| 832 |
+
else
|
| 833 |
+
$name = $type;
|
| 834 |
+
if (! $node) {
|
| 835 |
+
if (self::issetGlobal($documentID, $type)) {
|
| 836 |
+
$pq = phpQuery::getDocument($documentID);
|
| 837 |
+
// TODO check add($pq->document)
|
| 838 |
+
$pq->find('*')->add($pq->document)
|
| 839 |
+
->trigger($type, $data);
|
| 840 |
+
}
|
| 841 |
+
} else {
|
| 842 |
+
if (isset($data[0]) && $data[0] instanceof DOMEvent) {
|
| 843 |
+
$event = $data[0];
|
| 844 |
+
$event->relatedTarget = $event->target;
|
| 845 |
+
$event->target = $node;
|
| 846 |
+
$data = array_slice($data, 1);
|
| 847 |
+
} else {
|
| 848 |
+
$event = new DOMEvent(array(
|
| 849 |
+
'type' => $type,
|
| 850 |
+
'target' => $node,
|
| 851 |
+
'timeStamp' => time(),
|
| 852 |
+
));
|
| 853 |
+
}
|
| 854 |
+
$i = 0;
|
| 855 |
+
while($node) {
|
| 856 |
+
// TODO whois
|
| 857 |
+
phpQuery::debug("Triggering ".($i?"bubbled ":'')."event '{$type}' on "
|
| 858 |
+
."node \n");//.phpQueryObject::whois($node)."\n");
|
| 859 |
+
$event->currentTarget = $node;
|
| 860 |
+
$eventNode = self::getNode($documentID, $node);
|
| 861 |
+
if (isset($eventNode->eventHandlers)) {
|
| 862 |
+
foreach($eventNode->eventHandlers as $eventType => $handlers) {
|
| 863 |
+
$eventNamespace = null;
|
| 864 |
+
if (strpos($type, '.') !== false)
|
| 865 |
+
list($eventName, $eventNamespace) = explode('.', $eventType);
|
| 866 |
+
else
|
| 867 |
+
$eventName = $eventType;
|
| 868 |
+
if ($name != $eventName)
|
| 869 |
+
continue;
|
| 870 |
+
if ($namespace && $eventNamespace && $namespace != $eventNamespace)
|
| 871 |
+
continue;
|
| 872 |
+
foreach($handlers as $handler) {
|
| 873 |
+
phpQuery::debug("Calling event handler\n");
|
| 874 |
+
$event->data = $handler['data']
|
| 875 |
+
? $handler['data']
|
| 876 |
+
: null;
|
| 877 |
+
$params = array_merge(array($event), $data);
|
| 878 |
+
$return = phpQuery::callbackRun($handler['callback'], $params);
|
| 879 |
+
if ($return === false) {
|
| 880 |
+
$event->bubbles = false;
|
| 881 |
+
}
|
| 882 |
+
}
|
| 883 |
+
}
|
| 884 |
+
}
|
| 885 |
+
// to bubble or not to bubble...
|
| 886 |
+
if (! $event->bubbles)
|
| 887 |
+
break;
|
| 888 |
+
$node = $node->parentNode;
|
| 889 |
+
$i++;
|
| 890 |
+
}
|
| 891 |
+
}
|
| 892 |
+
}
|
| 893 |
+
/**
|
| 894 |
+
* Binds a handler to one or more events (like click) for each matched element.
|
| 895 |
+
* Can also bind custom events.
|
| 896 |
+
*
|
| 897 |
+
* @param DOMNode|phpQueryObject|string $document
|
| 898 |
+
* @param unknown_type $type
|
| 899 |
+
* @param unknown_type $data Optional
|
| 900 |
+
* @param unknown_type $callback
|
| 901 |
+
*
|
| 902 |
+
* @TODO support '!' (exclusive) events
|
| 903 |
+
* @TODO support more than event in $type (space-separated)
|
| 904 |
+
* @TODO support binding to global events
|
| 905 |
+
*/
|
| 906 |
+
public static function add($document, $node, $type, $data, $callback = null) {
|
| 907 |
+
phpQuery::debug("Binding '$type' event");
|
| 908 |
+
$documentID = phpQuery::getDocumentID($document);
|
| 909 |
+
// if (is_null($callback) && is_callable($data)) {
|
| 910 |
+
// $callback = $data;
|
| 911 |
+
// $data = null;
|
| 912 |
+
// }
|
| 913 |
+
$eventNode = self::getNode($documentID, $node);
|
| 914 |
+
if (! $eventNode)
|
| 915 |
+
$eventNode = self::setNode($documentID, $node);
|
| 916 |
+
if (!isset($eventNode->eventHandlers[$type]))
|
| 917 |
+
$eventNode->eventHandlers[$type] = array();
|
| 918 |
+
$eventNode->eventHandlers[$type][] = array(
|
| 919 |
+
'callback' => $callback,
|
| 920 |
+
'data' => $data,
|
| 921 |
+
);
|
| 922 |
+
}
|
| 923 |
+
/**
|
| 924 |
+
* Enter description here...
|
| 925 |
+
*
|
| 926 |
+
* @param DOMNode|phpQueryObject|string $document
|
| 927 |
+
* @param unknown_type $type
|
| 928 |
+
* @param unknown_type $callback
|
| 929 |
+
*
|
| 930 |
+
* @TODO namespace events
|
| 931 |
+
* @TODO support more than event in $type (space-separated)
|
| 932 |
+
*/
|
| 933 |
+
public static function remove($document, $node, $type = null, $callback = null) {
|
| 934 |
+
$documentID = phpQuery::getDocumentID($document);
|
| 935 |
+
$eventNode = self::getNode($documentID, $node);
|
| 936 |
+
if (is_object($eventNode) && isset($eventNode->eventHandlers[$type])) {
|
| 937 |
+
if ($callback) {
|
| 938 |
+
foreach($eventNode->eventHandlers[$type] as $k => $handler)
|
| 939 |
+
if ($handler['callback'] == $callback)
|
| 940 |
+
unset($eventNode->eventHandlers[$type][$k]);
|
| 941 |
+
} else {
|
| 942 |
+
unset($eventNode->eventHandlers[$type]);
|
| 943 |
+
}
|
| 944 |
+
}
|
| 945 |
+
}
|
| 946 |
+
protected static function getNode($documentID, $node) {
|
| 947 |
+
foreach(phpQuery::$documents[$documentID]->eventsNodes as $eventNode) {
|
| 948 |
+
if ($node->isSameNode($eventNode))
|
| 949 |
+
return $eventNode;
|
| 950 |
+
}
|
| 951 |
+
}
|
| 952 |
+
protected static function setNode($documentID, $node) {
|
| 953 |
+
phpQuery::$documents[$documentID]->eventsNodes[] = $node;
|
| 954 |
+
return phpQuery::$documents[$documentID]->eventsNodes[
|
| 955 |
+
count(phpQuery::$documents[$documentID]->eventsNodes)-1
|
| 956 |
+
];
|
| 957 |
+
}
|
| 958 |
+
protected static function issetGlobal($documentID, $type) {
|
| 959 |
+
return isset(phpQuery::$documents[$documentID])
|
| 960 |
+
? in_array($type, phpQuery::$documents[$documentID]->eventsGlobal)
|
| 961 |
+
: false;
|
| 962 |
+
}
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
|
| 966 |
+
interface ICallbackNamed {
|
| 967 |
+
function hasName();
|
| 968 |
+
function getName();
|
| 969 |
+
}
|
| 970 |
+
/**
|
| 971 |
+
* Callback class introduces currying-like pattern.
|
| 972 |
+
*
|
| 973 |
+
* Example:
|
| 974 |
+
* function foo($param1, $param2, $param3) {
|
| 975 |
+
* var_dump($param1, $param2, $param3);
|
| 976 |
+
* }
|
| 977 |
+
* $fooCurried = new Callback('foo',
|
| 978 |
+
* 'param1 is now statically set',
|
| 979 |
+
* new CallbackParam, new CallbackParam
|
| 980 |
+
* );
|
| 981 |
+
* phpQuery::callbackRun($fooCurried,
|
| 982 |
+
* array('param2 value', 'param3 value'
|
| 983 |
+
* );
|
| 984 |
+
*
|
| 985 |
+
* Callback class is supported in all phpQuery methods which accepts callbacks.
|
| 986 |
+
*
|
| 987 |
+
* @link http://code.google.com/p/phpquery/wiki/Callbacks#Param_Structures
|
| 988 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 989 |
+
*
|
| 990 |
+
* @TODO??? return fake forwarding function created via create_function
|
| 991 |
+
* @TODO honor paramStructure
|
| 992 |
+
*/
|
| 993 |
+
class Callback
|
| 994 |
+
implements ICallbackNamed {
|
| 995 |
+
public $callback = null;
|
| 996 |
+
public $params = null;
|
| 997 |
+
protected $name;
|
| 998 |
+
public function __construct($callback, $param1 = null, $param2 = null,
|
| 999 |
+
$param3 = null) {
|
| 1000 |
+
$params = func_get_args();
|
| 1001 |
+
$params = array_slice($params, 1);
|
| 1002 |
+
if ($callback instanceof Callback) {
|
| 1003 |
+
// TODO implement recurention
|
| 1004 |
+
} else {
|
| 1005 |
+
$this->callback = $callback;
|
| 1006 |
+
$this->params = $params;
|
| 1007 |
+
}
|
| 1008 |
+
}
|
| 1009 |
+
public function getName() {
|
| 1010 |
+
return 'Callback: '.$this->name;
|
| 1011 |
+
}
|
| 1012 |
+
public function hasName() {
|
| 1013 |
+
return isset($this->name) && $this->name;
|
| 1014 |
+
}
|
| 1015 |
+
public function setName($name) {
|
| 1016 |
+
$this->name = $name;
|
| 1017 |
+
return $this;
|
| 1018 |
+
}
|
| 1019 |
+
// TODO test me
|
| 1020 |
+
// public function addParams() {
|
| 1021 |
+
// $params = func_get_args();
|
| 1022 |
+
// return new Callback($this->callback, $this->params+$params);
|
| 1023 |
+
// }
|
| 1024 |
+
}
|
| 1025 |
+
/**
|
| 1026 |
+
* Shorthand for new Callback(create_function(...), ...);
|
| 1027 |
+
*
|
| 1028 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 1029 |
+
*/
|
| 1030 |
+
class CallbackBody extends Callback {
|
| 1031 |
+
public function __construct($paramList, $code, $param1 = null, $param2 = null,
|
| 1032 |
+
$param3 = null) {
|
| 1033 |
+
$params = func_get_args();
|
| 1034 |
+
$params = array_slice($params, 2);
|
| 1035 |
+
$this->callback = create_function($paramList, $code);
|
| 1036 |
+
$this->params = $params;
|
| 1037 |
+
}
|
| 1038 |
+
}
|
| 1039 |
+
/**
|
| 1040 |
+
* Callback type which on execution returns reference passed during creation.
|
| 1041 |
+
*
|
| 1042 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 1043 |
+
*/
|
| 1044 |
+
class CallbackReturnReference extends Callback
|
| 1045 |
+
implements ICallbackNamed {
|
| 1046 |
+
protected $reference;
|
| 1047 |
+
public function __construct(&$reference, $name = null){
|
| 1048 |
+
$this->reference =& $reference;
|
| 1049 |
+
$this->callback = array($this, 'callback');
|
| 1050 |
+
}
|
| 1051 |
+
public function callback() {
|
| 1052 |
+
return $this->reference;
|
| 1053 |
+
}
|
| 1054 |
+
public function getName() {
|
| 1055 |
+
return 'Callback: '.$this->name;
|
| 1056 |
+
}
|
| 1057 |
+
public function hasName() {
|
| 1058 |
+
return isset($this->name) && $this->name;
|
| 1059 |
+
}
|
| 1060 |
+
}
|
| 1061 |
+
/**
|
| 1062 |
+
* Callback type which on execution returns value passed during creation.
|
| 1063 |
+
*
|
| 1064 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 1065 |
+
*/
|
| 1066 |
+
class CallbackReturnValue extends Callback
|
| 1067 |
+
implements ICallbackNamed {
|
| 1068 |
+
protected $value;
|
| 1069 |
+
protected $name;
|
| 1070 |
+
public function __construct($value, $name = null){
|
| 1071 |
+
$this->value =& $value;
|
| 1072 |
+
$this->name = $name;
|
| 1073 |
+
$this->callback = array($this, 'callback');
|
| 1074 |
+
}
|
| 1075 |
+
public function callback() {
|
| 1076 |
+
return $this->value;
|
| 1077 |
+
}
|
| 1078 |
+
public function __toString() {
|
| 1079 |
+
return $this->getName();
|
| 1080 |
+
}
|
| 1081 |
+
public function getName() {
|
| 1082 |
+
return 'Callback: '.$this->name;
|
| 1083 |
+
}
|
| 1084 |
+
public function hasName() {
|
| 1085 |
+
return isset($this->name) && $this->name;
|
| 1086 |
+
}
|
| 1087 |
+
}
|
| 1088 |
+
/**
|
| 1089 |
+
* CallbackParameterToReference can be used when we don't really want a callback,
|
| 1090 |
+
* only parameter passed to it. CallbackParameterToReference takes first
|
| 1091 |
+
* parameter's value and passes it to reference.
|
| 1092 |
+
*
|
| 1093 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 1094 |
+
*/
|
| 1095 |
+
class CallbackParameterToReference extends Callback {
|
| 1096 |
+
/**
|
| 1097 |
+
* @param $reference
|
| 1098 |
+
* @TODO implement $paramIndex;
|
| 1099 |
+
* param index choose which callback param will be passed to reference
|
| 1100 |
+
*/
|
| 1101 |
+
public function __construct(&$reference){
|
| 1102 |
+
$this->callback =& $reference;
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
//class CallbackReference extends Callback {
|
| 1106 |
+
// /**
|
| 1107 |
+
// *
|
| 1108 |
+
// * @param $reference
|
| 1109 |
+
// * @param $paramIndex
|
| 1110 |
+
// * @todo implement $paramIndex; param index choose which callback param will be passed to reference
|
| 1111 |
+
// */
|
| 1112 |
+
// public function __construct(&$reference, $name = null){
|
| 1113 |
+
// $this->callback =& $reference;
|
| 1114 |
+
// }
|
| 1115 |
+
//}
|
| 1116 |
+
class CallbackParam {}
|
| 1117 |
+
|
| 1118 |
+
/**
|
| 1119 |
+
* Class representing phpQuery objects.
|
| 1120 |
+
*
|
| 1121 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 1122 |
+
* @package phpQuery
|
| 1123 |
+
* @method phpQueryObject clone() clone()
|
| 1124 |
+
* @method phpQueryObject empty() empty()
|
| 1125 |
+
* @method phpQueryObject next() next($selector = null)
|
| 1126 |
+
* @method phpQueryObject prev() prev($selector = null)
|
| 1127 |
+
* @property Int $length
|
| 1128 |
+
*/
|
| 1129 |
+
class phpQueryObject
|
| 1130 |
+
implements Iterator, Countable, ArrayAccess {
|
| 1131 |
+
public $documentID = null;
|
| 1132 |
+
/**
|
| 1133 |
+
* DOMDocument class.
|
| 1134 |
+
*
|
| 1135 |
+
* @var DOMDocument
|
| 1136 |
+
*/
|
| 1137 |
+
public $document = null;
|
| 1138 |
+
public $charset = null;
|
| 1139 |
+
/**
|
| 1140 |
+
*
|
| 1141 |
+
* @var DOMDocumentWrapper
|
| 1142 |
+
*/
|
| 1143 |
+
public $documentWrapper = null;
|
| 1144 |
+
/**
|
| 1145 |
+
* XPath interface.
|
| 1146 |
+
*
|
| 1147 |
+
* @var DOMXPath
|
| 1148 |
+
*/
|
| 1149 |
+
public $xpath = null;
|
| 1150 |
+
/**
|
| 1151 |
+
* Stack of selected elements.
|
| 1152 |
+
* @TODO refactor to ->nodes
|
| 1153 |
+
* @var array
|
| 1154 |
+
*/
|
| 1155 |
+
public $elements = array();
|
| 1156 |
+
/**
|
| 1157 |
+
* @access private
|
| 1158 |
+
*/
|
| 1159 |
+
protected $elementsBackup = array();
|
| 1160 |
+
/**
|
| 1161 |
+
* @access private
|
| 1162 |
+
*/
|
| 1163 |
+
protected $previous = null;
|
| 1164 |
+
/**
|
| 1165 |
+
* @access private
|
| 1166 |
+
* @TODO deprecate
|
| 1167 |
+
*/
|
| 1168 |
+
protected $root = array();
|
| 1169 |
+
/**
|
| 1170 |
+
* Indicated if doument is just a fragment (no <html> tag).
|
| 1171 |
+
*
|
| 1172 |
+
* Every document is realy a full document, so even documentFragments can
|
| 1173 |
+
* be queried against <html>, but getDocument(id)->htmlOuter() will return
|
| 1174 |
+
* only contents of <body>.
|
| 1175 |
+
*
|
| 1176 |
+
* @var bool
|
| 1177 |
+
*/
|
| 1178 |
+
public $documentFragment = true;
|
| 1179 |
+
/**
|
| 1180 |
+
* Iterator interface helper
|
| 1181 |
+
* @access private
|
| 1182 |
+
*/
|
| 1183 |
+
protected $elementsInterator = array();
|
| 1184 |
+
/**
|
| 1185 |
+
* Iterator interface helper
|
| 1186 |
+
* @access private
|
| 1187 |
+
*/
|
| 1188 |
+
protected $valid = false;
|
| 1189 |
+
/**
|
| 1190 |
+
* Iterator interface helper
|
| 1191 |
+
* @access private
|
| 1192 |
+
*/
|
| 1193 |
+
protected $current = null;
|
| 1194 |
+
/**
|
| 1195 |
+
* Enter description here...
|
| 1196 |
+
*
|
| 1197 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1198 |
+
*/
|
| 1199 |
+
public function __construct($documentID) {
|
| 1200 |
+
// if ($documentID instanceof self)
|
| 1201 |
+
// var_dump($documentID->getDocumentID());
|
| 1202 |
+
$id = $documentID instanceof self
|
| 1203 |
+
? $documentID->getDocumentID()
|
| 1204 |
+
: $documentID;
|
| 1205 |
+
// var_dump($id);
|
| 1206 |
+
if (! isset(phpQuery::$documents[$id] )) {
|
| 1207 |
+
// var_dump(phpQuery::$documents);
|
| 1208 |
+
throw new Exception("Document with ID '{$id}' isn't loaded. Use phpQuery::newDocument(\$html) or phpQuery::newDocumentFile(\$file) first.");
|
| 1209 |
+
}
|
| 1210 |
+
$this->documentID = $id;
|
| 1211 |
+
$this->documentWrapper =& phpQuery::$documents[$id];
|
| 1212 |
+
$this->document =& $this->documentWrapper->document;
|
| 1213 |
+
$this->xpath =& $this->documentWrapper->xpath;
|
| 1214 |
+
$this->charset =& $this->documentWrapper->charset;
|
| 1215 |
+
$this->documentFragment =& $this->documentWrapper->isDocumentFragment;
|
| 1216 |
+
// TODO check $this->DOM->documentElement;
|
| 1217 |
+
// $this->root = $this->document->documentElement;
|
| 1218 |
+
$this->root =& $this->documentWrapper->root;
|
| 1219 |
+
// $this->toRoot();
|
| 1220 |
+
$this->elements = array($this->root);
|
| 1221 |
+
}
|
| 1222 |
+
/**
|
| 1223 |
+
*
|
| 1224 |
+
* @access private
|
| 1225 |
+
* @param $attr
|
| 1226 |
+
* @return unknown_type
|
| 1227 |
+
*/
|
| 1228 |
+
public function __get($attr) {
|
| 1229 |
+
switch($attr) {
|
| 1230 |
+
// FIXME doesnt work at all ?
|
| 1231 |
+
case 'length':
|
| 1232 |
+
return $this->size();
|
| 1233 |
+
break;
|
| 1234 |
+
default:
|
| 1235 |
+
return $this->$attr;
|
| 1236 |
+
}
|
| 1237 |
+
}
|
| 1238 |
+
/**
|
| 1239 |
+
* Saves actual object to $var by reference.
|
| 1240 |
+
* Useful when need to break chain.
|
| 1241 |
+
* @param phpQueryObject $var
|
| 1242 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1243 |
+
*/
|
| 1244 |
+
public function toReference(&$var) {
|
| 1245 |
+
return $var = $this;
|
| 1246 |
+
}
|
| 1247 |
+
public function documentFragment($state = null) {
|
| 1248 |
+
if ($state) {
|
| 1249 |
+
phpQuery::$documents[$this->getDocumentID()]['documentFragment'] = $state;
|
| 1250 |
+
return $this;
|
| 1251 |
+
}
|
| 1252 |
+
return $this->documentFragment;
|
| 1253 |
+
}
|
| 1254 |
+
/**
|
| 1255 |
+
* @access private
|
| 1256 |
+
* @TODO documentWrapper
|
| 1257 |
+
*/
|
| 1258 |
+
protected function isRoot( $node) {
|
| 1259 |
+
// return $node instanceof DOMDOCUMENT || $node->tagName == 'html';
|
| 1260 |
+
return $node instanceof DOMDOCUMENT
|
| 1261 |
+
|| ($node instanceof DOMELEMENT && $node->tagName == 'html')
|
| 1262 |
+
|| $this->root->isSameNode($node);
|
| 1263 |
+
}
|
| 1264 |
+
/**
|
| 1265 |
+
* @access private
|
| 1266 |
+
*/
|
| 1267 |
+
protected function stackIsRoot() {
|
| 1268 |
+
return $this->size() == 1 && $this->isRoot($this->elements[0]);
|
| 1269 |
+
}
|
| 1270 |
+
/**
|
| 1271 |
+
* Enter description here...
|
| 1272 |
+
* NON JQUERY METHOD
|
| 1273 |
+
*
|
| 1274 |
+
* Watch out, it doesn't creates new instance, can be reverted with end().
|
| 1275 |
+
*
|
| 1276 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1277 |
+
*/
|
| 1278 |
+
public function toRoot() {
|
| 1279 |
+
$this->elements = array($this->root);
|
| 1280 |
+
return $this;
|
| 1281 |
+
// return $this->newInstance(array($this->root));
|
| 1282 |
+
}
|
| 1283 |
+
/**
|
| 1284 |
+
* Saves object's DocumentID to $var by reference.
|
| 1285 |
+
* <code>
|
| 1286 |
+
* $myDocumentId;
|
| 1287 |
+
* phpQuery::newDocument('<div/>')
|
| 1288 |
+
* ->getDocumentIDRef($myDocumentId)
|
| 1289 |
+
* ->find('div')->...
|
| 1290 |
+
* </code>
|
| 1291 |
+
*
|
| 1292 |
+
* @param unknown_type $domId
|
| 1293 |
+
* @see phpQuery::newDocument
|
| 1294 |
+
* @see phpQuery::newDocumentFile
|
| 1295 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1296 |
+
*/
|
| 1297 |
+
public function getDocumentIDRef(&$documentID) {
|
| 1298 |
+
$documentID = $this->getDocumentID();
|
| 1299 |
+
return $this;
|
| 1300 |
+
}
|
| 1301 |
+
/**
|
| 1302 |
+
* Returns object with stack set to document root.
|
| 1303 |
+
*
|
| 1304 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1305 |
+
*/
|
| 1306 |
+
public function getDocument() {
|
| 1307 |
+
return phpQuery::getDocument($this->getDocumentID());
|
| 1308 |
+
}
|
| 1309 |
+
/**
|
| 1310 |
+
*
|
| 1311 |
+
* @return DOMDocument
|
| 1312 |
+
*/
|
| 1313 |
+
public function getDOMDocument() {
|
| 1314 |
+
return $this->document;
|
| 1315 |
+
}
|
| 1316 |
+
/**
|
| 1317 |
+
* Get object's Document ID.
|
| 1318 |
+
*
|
| 1319 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1320 |
+
*/
|
| 1321 |
+
public function getDocumentID() {
|
| 1322 |
+
return $this->documentID;
|
| 1323 |
+
}
|
| 1324 |
+
/**
|
| 1325 |
+
* Unloads whole document from memory.
|
| 1326 |
+
* CAUTION! None further operations will be possible on this document.
|
| 1327 |
+
* All objects refering to it will be useless.
|
| 1328 |
+
*
|
| 1329 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1330 |
+
*/
|
| 1331 |
+
public function unloadDocument() {
|
| 1332 |
+
phpQuery::unloadDocuments($this->getDocumentID());
|
| 1333 |
+
}
|
| 1334 |
+
public function isHTML() {
|
| 1335 |
+
return $this->documentWrapper->isHTML;
|
| 1336 |
+
}
|
| 1337 |
+
public function isXHTML() {
|
| 1338 |
+
return $this->documentWrapper->isXHTML;
|
| 1339 |
+
}
|
| 1340 |
+
public function isXML() {
|
| 1341 |
+
return $this->documentWrapper->isXML;
|
| 1342 |
+
}
|
| 1343 |
+
/**
|
| 1344 |
+
* Enter description here...
|
| 1345 |
+
*
|
| 1346 |
+
* @link http://docs.jquery.com/Ajax/serialize
|
| 1347 |
+
* @return string
|
| 1348 |
+
*/
|
| 1349 |
+
public function serialize() {
|
| 1350 |
+
return phpQuery::param($this->serializeArray());
|
| 1351 |
+
}
|
| 1352 |
+
/**
|
| 1353 |
+
* Enter description here...
|
| 1354 |
+
*
|
| 1355 |
+
* @link http://docs.jquery.com/Ajax/serializeArray
|
| 1356 |
+
* @return array
|
| 1357 |
+
*/
|
| 1358 |
+
public function serializeArray($submit = null) {
|
| 1359 |
+
$source = $this->filter('form, input, select, textarea')
|
| 1360 |
+
->find('input, select, textarea')
|
| 1361 |
+
->andSelf()
|
| 1362 |
+
->not('form');
|
| 1363 |
+
$return = array();
|
| 1364 |
+
// $source->dumpDie();
|
| 1365 |
+
foreach($source as $input) {
|
| 1366 |
+
$input = phpQuery::pq($input);
|
| 1367 |
+
if ($input->is('[disabled]'))
|
| 1368 |
+
continue;
|
| 1369 |
+
if (!$input->is('[name]'))
|
| 1370 |
+
continue;
|
| 1371 |
+
if ($input->is('[type=checkbox]') && !$input->is('[checked]'))
|
| 1372 |
+
continue;
|
| 1373 |
+
// jquery diff
|
| 1374 |
+
if ($submit && $input->is('[type=submit]')) {
|
| 1375 |
+
if ($submit instanceof DOMELEMENT && ! $input->elements[0]->isSameNode($submit))
|
| 1376 |
+
continue;
|
| 1377 |
+
else if (is_string($submit) && $input->attr('name') != $submit)
|
| 1378 |
+
continue;
|
| 1379 |
+
}
|
| 1380 |
+
$return[] = array(
|
| 1381 |
+
'name' => $input->attr('name'),
|
| 1382 |
+
'value' => $input->val(),
|
| 1383 |
+
);
|
| 1384 |
+
}
|
| 1385 |
+
return $return;
|
| 1386 |
+
}
|
| 1387 |
+
/**
|
| 1388 |
+
* @access private
|
| 1389 |
+
*/
|
| 1390 |
+
protected function debug($in) {
|
| 1391 |
+
if (! phpQuery::$debug )
|
| 1392 |
+
return;
|
| 1393 |
+
print('<pre>');
|
| 1394 |
+
print_r($in);
|
| 1395 |
+
// file debug
|
| 1396 |
+
// file_put_contents(dirname(__FILE__).'/phpQuery.log', print_r($in, true)."\n", FILE_APPEND);
|
| 1397 |
+
// quite handy debug trace
|
| 1398 |
+
// if ( is_array($in))
|
| 1399 |
+
// print_r(array_slice(debug_backtrace(), 3));
|
| 1400 |
+
print("</pre>\n");
|
| 1401 |
+
}
|
| 1402 |
+
/**
|
| 1403 |
+
* @access private
|
| 1404 |
+
*/
|
| 1405 |
+
protected function isRegexp($pattern) {
|
| 1406 |
+
return in_array(
|
| 1407 |
+
$pattern[ mb_strlen($pattern)-1 ],
|
| 1408 |
+
array('^','*','$')
|
| 1409 |
+
);
|
| 1410 |
+
}
|
| 1411 |
+
/**
|
| 1412 |
+
* Determines if $char is really a char.
|
| 1413 |
+
*
|
| 1414 |
+
* @param string $char
|
| 1415 |
+
* @return bool
|
| 1416 |
+
* @todo rewrite me to charcode range ! ;)
|
| 1417 |
+
* @access private
|
| 1418 |
+
*/
|
| 1419 |
+
protected function isChar($char) {
|
| 1420 |
+
return extension_loaded('mbstring') && phpQuery::$mbstringSupport
|
| 1421 |
+
? mb_eregi('\w', $char)
|
| 1422 |
+
: preg_match('@\w@', $char);
|
| 1423 |
+
}
|
| 1424 |
+
/**
|
| 1425 |
+
* @access private
|
| 1426 |
+
*/
|
| 1427 |
+
protected function parseSelector($query) {
|
| 1428 |
+
// clean spaces
|
| 1429 |
+
// TODO include this inside parsing ?
|
| 1430 |
+
$query = trim(
|
| 1431 |
+
preg_replace('@\s+@', ' ',
|
| 1432 |
+
preg_replace('@\s*(>|\\+|~)\s*@', '\\1', $query)
|
| 1433 |
+
)
|
| 1434 |
+
);
|
| 1435 |
+
$queries = array(array());
|
| 1436 |
+
if (! $query)
|
| 1437 |
+
return $queries;
|
| 1438 |
+
$return =& $queries[0];
|
| 1439 |
+
$specialChars = array('>',' ');
|
| 1440 |
+
// $specialCharsMapping = array('/' => '>');
|
| 1441 |
+
$specialCharsMapping = array();
|
| 1442 |
+
$strlen = mb_strlen($query);
|
| 1443 |
+
$classChars = array('.', '-');
|
| 1444 |
+
$pseudoChars = array('-');
|
| 1445 |
+
$tagChars = array('*', '|', '-');
|
| 1446 |
+
// split multibyte string
|
| 1447 |
+
// http://code.google.com/p/phpquery/issues/detail?id=76
|
| 1448 |
+
$_query = array();
|
| 1449 |
+
for ($i=0; $i<$strlen; $i++)
|
| 1450 |
+
$_query[] = mb_substr($query, $i, 1);
|
| 1451 |
+
$query = $_query;
|
| 1452 |
+
// it works, but i dont like it...
|
| 1453 |
+
$i = 0;
|
| 1454 |
+
while( $i < $strlen) {
|
| 1455 |
+
$c = $query[$i];
|
| 1456 |
+
$tmp = '';
|
| 1457 |
+
// TAG
|
| 1458 |
+
if ($this->isChar($c) || in_array($c, $tagChars)) {
|
| 1459 |
+
while(isset($query[$i])
|
| 1460 |
+
&& ($this->isChar($query[$i]) || in_array($query[$i], $tagChars))) {
|
| 1461 |
+
$tmp .= $query[$i];
|
| 1462 |
+
$i++;
|
| 1463 |
+
}
|
| 1464 |
+
$return[] = $tmp;
|
| 1465 |
+
// IDs
|
| 1466 |
+
} else if ( $c == '#') {
|
| 1467 |
+
$i++;
|
| 1468 |
+
while( isset($query[$i]) && ($this->isChar($query[$i]) || $query[$i] == '-')) {
|
| 1469 |
+
$tmp .= $query[$i];
|
| 1470 |
+
$i++;
|
| 1471 |
+
}
|
| 1472 |
+
$return[] = '#'.$tmp;
|
| 1473 |
+
// SPECIAL CHARS
|
| 1474 |
+
} else if (in_array($c, $specialChars)) {
|
| 1475 |
+
$return[] = $c;
|
| 1476 |
+
$i++;
|
| 1477 |
+
// MAPPED SPECIAL MULTICHARS
|
| 1478 |
+
// } else if ( $c.$query[$i+1] == '//') {
|
| 1479 |
+
// $return[] = ' ';
|
| 1480 |
+
// $i = $i+2;
|
| 1481 |
+
// MAPPED SPECIAL CHARS
|
| 1482 |
+
} else if ( isset($specialCharsMapping[$c])) {
|
| 1483 |
+
$return[] = $specialCharsMapping[$c];
|
| 1484 |
+
$i++;
|
| 1485 |
+
// COMMA
|
| 1486 |
+
} else if ( $c == ',') {
|
| 1487 |
+
$queries[] = array();
|
| 1488 |
+
$return =& $queries[ count($queries)-1 ];
|
| 1489 |
+
$i++;
|
| 1490 |
+
while( isset($query[$i]) && $query[$i] == ' ')
|
| 1491 |
+
$i++;
|
| 1492 |
+
// CLASSES
|
| 1493 |
+
} else if ($c == '.') {
|
| 1494 |
+
while( isset($query[$i]) && ($this->isChar($query[$i]) || in_array($query[$i], $classChars))) {
|
| 1495 |
+
$tmp .= $query[$i];
|
| 1496 |
+
$i++;
|
| 1497 |
+
}
|
| 1498 |
+
$return[] = $tmp;
|
| 1499 |
+
// ~ General Sibling Selector
|
| 1500 |
+
} else if ($c == '~') {
|
| 1501 |
+
$spaceAllowed = true;
|
| 1502 |
+
$tmp .= $query[$i++];
|
| 1503 |
+
while( isset($query[$i])
|
| 1504 |
+
&& ($this->isChar($query[$i])
|
| 1505 |
+
|| in_array($query[$i], $classChars)
|
| 1506 |
+
|| $query[$i] == '*'
|
| 1507 |
+
|| ($query[$i] == ' ' && $spaceAllowed)
|
| 1508 |
+
)) {
|
| 1509 |
+
if ($query[$i] != ' ')
|
| 1510 |
+
$spaceAllowed = false;
|
| 1511 |
+
$tmp .= $query[$i];
|
| 1512 |
+
$i++;
|
| 1513 |
+
}
|
| 1514 |
+
$return[] = $tmp;
|
| 1515 |
+
// + Adjacent sibling selectors
|
| 1516 |
+
} else if ($c == '+') {
|
| 1517 |
+
$spaceAllowed = true;
|
| 1518 |
+
$tmp .= $query[$i++];
|
| 1519 |
+
while( isset($query[$i])
|
| 1520 |
+
&& ($this->isChar($query[$i])
|
| 1521 |
+
|| in_array($query[$i], $classChars)
|
| 1522 |
+
|| $query[$i] == '*'
|
| 1523 |
+
|| ($spaceAllowed && $query[$i] == ' ')
|
| 1524 |
+
)) {
|
| 1525 |
+
if ($query[$i] != ' ')
|
| 1526 |
+
$spaceAllowed = false;
|
| 1527 |
+
$tmp .= $query[$i];
|
| 1528 |
+
$i++;
|
| 1529 |
+
}
|
| 1530 |
+
$return[] = $tmp;
|
| 1531 |
+
// ATTRS
|
| 1532 |
+
} else if ($c == '[') {
|
| 1533 |
+
$stack = 1;
|
| 1534 |
+
$tmp .= $c;
|
| 1535 |
+
while( isset($query[++$i])) {
|
| 1536 |
+
$tmp .= $query[$i];
|
| 1537 |
+
if ( $query[$i] == '[') {
|
| 1538 |
+
$stack++;
|
| 1539 |
+
} else if ( $query[$i] == ']') {
|
| 1540 |
+
$stack--;
|
| 1541 |
+
if (! $stack )
|
| 1542 |
+
break;
|
| 1543 |
+
}
|
| 1544 |
+
}
|
| 1545 |
+
$return[] = $tmp;
|
| 1546 |
+
$i++;
|
| 1547 |
+
// PSEUDO CLASSES
|
| 1548 |
+
} else if ($c == ':') {
|
| 1549 |
+
$stack = 1;
|
| 1550 |
+
$tmp .= $query[$i++];
|
| 1551 |
+
while( isset($query[$i]) && ($this->isChar($query[$i]) || in_array($query[$i], $pseudoChars))) {
|
| 1552 |
+
$tmp .= $query[$i];
|
| 1553 |
+
$i++;
|
| 1554 |
+
}
|
| 1555 |
+
// with arguments ?
|
| 1556 |
+
if ( isset($query[$i]) && $query[$i] == '(') {
|
| 1557 |
+
$tmp .= $query[$i];
|
| 1558 |
+
$stack = 1;
|
| 1559 |
+
while( isset($query[++$i])) {
|
| 1560 |
+
$tmp .= $query[$i];
|
| 1561 |
+
if ( $query[$i] == '(') {
|
| 1562 |
+
$stack++;
|
| 1563 |
+
} else if ( $query[$i] == ')') {
|
| 1564 |
+
$stack--;
|
| 1565 |
+
if (! $stack )
|
| 1566 |
+
break;
|
| 1567 |
+
}
|
| 1568 |
+
}
|
| 1569 |
+
$return[] = $tmp;
|
| 1570 |
+
$i++;
|
| 1571 |
+
} else {
|
| 1572 |
+
$return[] = $tmp;
|
| 1573 |
+
}
|
| 1574 |
+
} else {
|
| 1575 |
+
$i++;
|
| 1576 |
+
}
|
| 1577 |
+
}
|
| 1578 |
+
foreach($queries as $k => $q) {
|
| 1579 |
+
if (isset($q[0])) {
|
| 1580 |
+
if (isset($q[0][0]) && $q[0][0] == ':')
|
| 1581 |
+
array_unshift($queries[$k], '*');
|
| 1582 |
+
if ($q[0] != '>')
|
| 1583 |
+
array_unshift($queries[$k], ' ');
|
| 1584 |
+
}
|
| 1585 |
+
}
|
| 1586 |
+
return $queries;
|
| 1587 |
+
}
|
| 1588 |
+
/**
|
| 1589 |
+
* Return matched DOM nodes.
|
| 1590 |
+
*
|
| 1591 |
+
* @param int $index
|
| 1592 |
+
* @return array|DOMElement Single DOMElement or array of DOMElement.
|
| 1593 |
+
*/
|
| 1594 |
+
public function get($index = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 1595 |
+
$return = isset($index)
|
| 1596 |
+
? (isset($this->elements[$index]) ? $this->elements[$index] : null)
|
| 1597 |
+
: $this->elements;
|
| 1598 |
+
// pass thou callbacks
|
| 1599 |
+
$args = func_get_args();
|
| 1600 |
+
$args = array_slice($args, 1);
|
| 1601 |
+
foreach($args as $callback) {
|
| 1602 |
+
if (is_array($return))
|
| 1603 |
+
foreach($return as $k => $v)
|
| 1604 |
+
$return[$k] = phpQuery::callbackRun($callback, array($v));
|
| 1605 |
+
else
|
| 1606 |
+
$return = phpQuery::callbackRun($callback, array($return));
|
| 1607 |
+
}
|
| 1608 |
+
return $return;
|
| 1609 |
+
}
|
| 1610 |
+
/**
|
| 1611 |
+
* Return matched DOM nodes.
|
| 1612 |
+
* jQuery difference.
|
| 1613 |
+
*
|
| 1614 |
+
* @param int $index
|
| 1615 |
+
* @return array|string Returns string if $index != null
|
| 1616 |
+
* @todo implement callbacks
|
| 1617 |
+
* @todo return only arrays ?
|
| 1618 |
+
* @todo maybe other name...
|
| 1619 |
+
*/
|
| 1620 |
+
public function getString($index = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 1621 |
+
if ($index)
|
| 1622 |
+
$return = $this->eq($index)->text();
|
| 1623 |
+
else {
|
| 1624 |
+
$return = array();
|
| 1625 |
+
for($i = 0; $i < $this->size(); $i++) {
|
| 1626 |
+
$return[] = $this->eq($i)->text();
|
| 1627 |
+
}
|
| 1628 |
+
}
|
| 1629 |
+
// pass thou callbacks
|
| 1630 |
+
$args = func_get_args();
|
| 1631 |
+
$args = array_slice($args, 1);
|
| 1632 |
+
foreach($args as $callback) {
|
| 1633 |
+
$return = phpQuery::callbackRun($callback, array($return));
|
| 1634 |
+
}
|
| 1635 |
+
return $return;
|
| 1636 |
+
}
|
| 1637 |
+
/**
|
| 1638 |
+
* Return matched DOM nodes.
|
| 1639 |
+
* jQuery difference.
|
| 1640 |
+
*
|
| 1641 |
+
* @param int $index
|
| 1642 |
+
* @return array|string Returns string if $index != null
|
| 1643 |
+
* @todo implement callbacks
|
| 1644 |
+
* @todo return only arrays ?
|
| 1645 |
+
* @todo maybe other name...
|
| 1646 |
+
*/
|
| 1647 |
+
public function getStrings($index = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 1648 |
+
if ($index)
|
| 1649 |
+
$return = $this->eq($index)->text();
|
| 1650 |
+
else {
|
| 1651 |
+
$return = array();
|
| 1652 |
+
for($i = 0; $i < $this->size(); $i++) {
|
| 1653 |
+
$return[] = $this->eq($i)->text();
|
| 1654 |
+
}
|
| 1655 |
+
// pass thou callbacks
|
| 1656 |
+
$args = func_get_args();
|
| 1657 |
+
$args = array_slice($args, 1);
|
| 1658 |
+
}
|
| 1659 |
+
foreach($args as $callback) {
|
| 1660 |
+
if (is_array($return))
|
| 1661 |
+
foreach($return as $k => $v)
|
| 1662 |
+
$return[$k] = phpQuery::callbackRun($callback, array($v));
|
| 1663 |
+
else
|
| 1664 |
+
$return = phpQuery::callbackRun($callback, array($return));
|
| 1665 |
+
}
|
| 1666 |
+
return $return;
|
| 1667 |
+
}
|
| 1668 |
+
/**
|
| 1669 |
+
* Returns new instance of actual class.
|
| 1670 |
+
*
|
| 1671 |
+
* @param array $newStack Optional. Will replace old stack with new and move old one to history.c
|
| 1672 |
+
*/
|
| 1673 |
+
public function newInstance($newStack = null) {
|
| 1674 |
+
$class = get_class($this);
|
| 1675 |
+
// support inheritance by passing old object to overloaded constructor
|
| 1676 |
+
$new = $class != 'phpQuery'
|
| 1677 |
+
? new $class($this, $this->getDocumentID())
|
| 1678 |
+
: new phpQueryObject($this->getDocumentID());
|
| 1679 |
+
$new->previous = $this;
|
| 1680 |
+
if (is_null($newStack)) {
|
| 1681 |
+
$new->elements = $this->elements;
|
| 1682 |
+
if ($this->elementsBackup)
|
| 1683 |
+
$this->elements = $this->elementsBackup;
|
| 1684 |
+
} else if (is_string($newStack)) {
|
| 1685 |
+
$new->elements = phpQuery::pq($newStack, $this->getDocumentID())->stack();
|
| 1686 |
+
} else {
|
| 1687 |
+
$new->elements = $newStack;
|
| 1688 |
+
}
|
| 1689 |
+
return $new;
|
| 1690 |
+
}
|
| 1691 |
+
/**
|
| 1692 |
+
* Enter description here...
|
| 1693 |
+
*
|
| 1694 |
+
* In the future, when PHP will support XLS 2.0, then we would do that this way:
|
| 1695 |
+
* contains(tokenize(@class, '\s'), "something")
|
| 1696 |
+
* @param unknown_type $class
|
| 1697 |
+
* @param unknown_type $node
|
| 1698 |
+
* @return boolean
|
| 1699 |
+
* @access private
|
| 1700 |
+
*/
|
| 1701 |
+
protected function matchClasses($class, $node) {
|
| 1702 |
+
// multi-class
|
| 1703 |
+
if ( mb_strpos($class, '.', 1)) {
|
| 1704 |
+
$classes = explode('.', substr($class, 1));
|
| 1705 |
+
$classesCount = count( $classes );
|
| 1706 |
+
$nodeClasses = explode(' ', $node->getAttribute('class') );
|
| 1707 |
+
$nodeClassesCount = count( $nodeClasses );
|
| 1708 |
+
if ( $classesCount > $nodeClassesCount )
|
| 1709 |
+
return false;
|
| 1710 |
+
$diff = count(
|
| 1711 |
+
array_diff(
|
| 1712 |
+
$classes,
|
| 1713 |
+
$nodeClasses
|
| 1714 |
+
)
|
| 1715 |
+
);
|
| 1716 |
+
if (! $diff )
|
| 1717 |
+
return true;
|
| 1718 |
+
// single-class
|
| 1719 |
+
} else {
|
| 1720 |
+
return in_array(
|
| 1721 |
+
// strip leading dot from class name
|
| 1722 |
+
substr($class, 1),
|
| 1723 |
+
// get classes for element as array
|
| 1724 |
+
explode(' ', $node->getAttribute('class') )
|
| 1725 |
+
);
|
| 1726 |
+
}
|
| 1727 |
+
}
|
| 1728 |
+
/**
|
| 1729 |
+
* @access private
|
| 1730 |
+
*/
|
| 1731 |
+
protected function runQuery($XQuery, $selector = null, $compare = null) {
|
| 1732 |
+
if ($compare && ! method_exists($this, $compare))
|
| 1733 |
+
return false;
|
| 1734 |
+
$stack = array();
|
| 1735 |
+
if (! $this->elements)
|
| 1736 |
+
$this->debug('Stack empty, skipping...');
|
| 1737 |
+
// var_dump($this->elements[0]->nodeType);
|
| 1738 |
+
// element, document
|
| 1739 |
+
foreach($this->stack(array(1, 9, 13)) as $k => $stackNode) {
|
| 1740 |
+
$detachAfter = false;
|
| 1741 |
+
// to work on detached nodes we need temporary place them somewhere
|
| 1742 |
+
// thats because context xpath queries sucks ;]
|
| 1743 |
+
$testNode = $stackNode;
|
| 1744 |
+
while ($testNode) {
|
| 1745 |
+
if (! $testNode->parentNode && ! $this->isRoot($testNode)) {
|
| 1746 |
+
$this->root->appendChild($testNode);
|
| 1747 |
+
$detachAfter = $testNode;
|
| 1748 |
+
break;
|
| 1749 |
+
}
|
| 1750 |
+
$testNode = isset($testNode->parentNode)
|
| 1751 |
+
? $testNode->parentNode
|
| 1752 |
+
: null;
|
| 1753 |
+
}
|
| 1754 |
+
// XXX tmp ?
|
| 1755 |
+
$xpath = $this->documentWrapper->isXHTML
|
| 1756 |
+
? $this->getNodeXpath($stackNode, 'html')
|
| 1757 |
+
: $this->getNodeXpath($stackNode);
|
| 1758 |
+
// FIXME pseudoclasses-only query, support XML
|
| 1759 |
+
$query = $XQuery == '//' && $xpath == '/html[1]'
|
| 1760 |
+
? '//*'
|
| 1761 |
+
: $xpath.$XQuery;
|
| 1762 |
+
$this->debug("XPATH: {$query}");
|
| 1763 |
+
// run query, get elements
|
| 1764 |
+
$nodes = $this->xpath->query($query);
|
| 1765 |
+
$this->debug("QUERY FETCHED");
|
| 1766 |
+
if (! $nodes->length )
|
| 1767 |
+
$this->debug('Nothing found');
|
| 1768 |
+
$debug = array();
|
| 1769 |
+
foreach($nodes as $node) {
|
| 1770 |
+
$matched = false;
|
| 1771 |
+
if ( $compare) {
|
| 1772 |
+
phpQuery::$debug ?
|
| 1773 |
+
$this->debug("Found: ".$this->whois( $node ).", comparing with {$compare}()")
|
| 1774 |
+
: null;
|
| 1775 |
+
$phpQueryDebug = phpQuery::$debug;
|
| 1776 |
+
phpQuery::$debug = false;
|
| 1777 |
+
// TODO ??? use phpQuery::callbackRun()
|
| 1778 |
+
if (call_user_func_array(array($this, $compare), array($selector, $node)))
|
| 1779 |
+
$matched = true;
|
| 1780 |
+
phpQuery::$debug = $phpQueryDebug;
|
| 1781 |
+
} else {
|
| 1782 |
+
$matched = true;
|
| 1783 |
+
}
|
| 1784 |
+
if ( $matched) {
|
| 1785 |
+
if (phpQuery::$debug)
|
| 1786 |
+
$debug[] = $this->whois( $node );
|
| 1787 |
+
$stack[] = $node;
|
| 1788 |
+
}
|
| 1789 |
+
}
|
| 1790 |
+
if (phpQuery::$debug) {
|
| 1791 |
+
$this->debug("Matched ".count($debug).": ".implode(', ', $debug));
|
| 1792 |
+
}
|
| 1793 |
+
if ($detachAfter)
|
| 1794 |
+
$this->root->removeChild($detachAfter);
|
| 1795 |
+
}
|
| 1796 |
+
$this->elements = $stack;
|
| 1797 |
+
}
|
| 1798 |
+
/**
|
| 1799 |
+
* Enter description here...
|
| 1800 |
+
*
|
| 1801 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 1802 |
+
*/
|
| 1803 |
+
public function find($selectors, $context = null, $noHistory = false) {
|
| 1804 |
+
if (!$noHistory)
|
| 1805 |
+
// backup last stack /for end()/
|
| 1806 |
+
$this->elementsBackup = $this->elements;
|
| 1807 |
+
// allow to define context
|
| 1808 |
+
// TODO combine code below with phpQuery::pq() context guessing code
|
| 1809 |
+
// as generic function
|
| 1810 |
+
if ($context) {
|
| 1811 |
+
if (! is_array($context) && $context instanceof DOMELEMENT)
|
| 1812 |
+
$this->elements = array($context);
|
| 1813 |
+
else if (is_array($context)) {
|
| 1814 |
+
$this->elements = array();
|
| 1815 |
+
foreach ($context as $c)
|
| 1816 |
+
if ($c instanceof DOMELEMENT)
|
| 1817 |
+
$this->elements[] = $c;
|
| 1818 |
+
} else if ( $context instanceof self )
|
| 1819 |
+
$this->elements = $context->elements;
|
| 1820 |
+
}
|
| 1821 |
+
$queries = $this->parseSelector($selectors);
|
| 1822 |
+
$this->debug(array('FIND', $selectors, $queries));
|
| 1823 |
+
$XQuery = '';
|
| 1824 |
+
// remember stack state because of multi-queries
|
| 1825 |
+
$oldStack = $this->elements;
|
| 1826 |
+
// here we will be keeping found elements
|
| 1827 |
+
$stack = array();
|
| 1828 |
+
foreach($queries as $selector) {
|
| 1829 |
+
$this->elements = $oldStack;
|
| 1830 |
+
$delimiterBefore = false;
|
| 1831 |
+
foreach($selector as $s) {
|
| 1832 |
+
// TAG
|
| 1833 |
+
$isTag = extension_loaded('mbstring') && phpQuery::$mbstringSupport
|
| 1834 |
+
? mb_ereg_match('^[\w|\||-]+$', $s) || $s == '*'
|
| 1835 |
+
: preg_match('@^[\w|\||-]+$@', $s) || $s == '*';
|
| 1836 |
+
if ($isTag) {
|
| 1837 |
+
if ($this->isXML()) {
|
| 1838 |
+
// namespace support
|
| 1839 |
+
if (mb_strpos($s, '|') !== false) {
|
| 1840 |
+
$ns = $tag = null;
|
| 1841 |
+
list($ns, $tag) = explode('|', $s);
|
| 1842 |
+
$XQuery .= "$ns:$tag";
|
| 1843 |
+
} else if ($s == '*') {
|
| 1844 |
+
$XQuery .= "*";
|
| 1845 |
+
} else {
|
| 1846 |
+
$XQuery .= "*[local-name()='$s']";
|
| 1847 |
+
}
|
| 1848 |
+
} else {
|
| 1849 |
+
$XQuery .= $s;
|
| 1850 |
+
}
|
| 1851 |
+
// ID
|
| 1852 |
+
} else if ($s[0] == '#') {
|
| 1853 |
+
if ($delimiterBefore)
|
| 1854 |
+
$XQuery .= '*';
|
| 1855 |
+
$XQuery .= "[@id='".substr($s, 1)."']";
|
| 1856 |
+
// ATTRIBUTES
|
| 1857 |
+
} else if ($s[0] == '[') {
|
| 1858 |
+
if ($delimiterBefore)
|
| 1859 |
+
$XQuery .= '*';
|
| 1860 |
+
// strip side brackets
|
| 1861 |
+
$attr = trim($s, '][');
|
| 1862 |
+
$execute = false;
|
| 1863 |
+
// attr with specifed value
|
| 1864 |
+
if (mb_strpos($s, '=')) {
|
| 1865 |
+
$value = null;
|
| 1866 |
+
list($attr, $value) = explode('=', $attr);
|
| 1867 |
+
$value = trim($value, "'\"");
|
| 1868 |
+
if ($this->isRegexp($attr)) {
|
| 1869 |
+
// cut regexp character
|
| 1870 |
+
$attr = substr($attr, 0, -1);
|
| 1871 |
+
$execute = true;
|
| 1872 |
+
$XQuery .= "[@{$attr}]";
|
| 1873 |
+
} else {
|
| 1874 |
+
$XQuery .= "[@{$attr}='{$value}']";
|
| 1875 |
+
}
|
| 1876 |
+
// attr without specified value
|
| 1877 |
+
} else {
|
| 1878 |
+
$XQuery .= "[@{$attr}]";
|
| 1879 |
+
}
|
| 1880 |
+
if ($execute) {
|
| 1881 |
+
$this->runQuery($XQuery, $s, 'is');
|
| 1882 |
+
$XQuery = '';
|
| 1883 |
+
if (! $this->length())
|
| 1884 |
+
break;
|
| 1885 |
+
}
|
| 1886 |
+
// CLASSES
|
| 1887 |
+
} else if ($s[0] == '.') {
|
| 1888 |
+
// TODO use return $this->find("./self::*[contains(concat(\" \",@class,\" \"), \" $class \")]");
|
| 1889 |
+
// thx wizDom ;)
|
| 1890 |
+
if ($delimiterBefore)
|
| 1891 |
+
$XQuery .= '*';
|
| 1892 |
+
$XQuery .= '[@class]';
|
| 1893 |
+
$this->runQuery($XQuery, $s, 'matchClasses');
|
| 1894 |
+
$XQuery = '';
|
| 1895 |
+
if (! $this->length() )
|
| 1896 |
+
break;
|
| 1897 |
+
// ~ General Sibling Selector
|
| 1898 |
+
} else if ($s[0] == '~') {
|
| 1899 |
+
$this->runQuery($XQuery);
|
| 1900 |
+
$XQuery = '';
|
| 1901 |
+
$this->elements = $this
|
| 1902 |
+
->siblings(
|
| 1903 |
+
substr($s, 1)
|
| 1904 |
+
)->elements;
|
| 1905 |
+
if (! $this->length() )
|
| 1906 |
+
break;
|
| 1907 |
+
// + Adjacent sibling selectors
|
| 1908 |
+
} else if ($s[0] == '+') {
|
| 1909 |
+
// TODO /following-sibling::
|
| 1910 |
+
$this->runQuery($XQuery);
|
| 1911 |
+
$XQuery = '';
|
| 1912 |
+
$subSelector = substr($s, 1);
|
| 1913 |
+
$subElements = $this->elements;
|
| 1914 |
+
$this->elements = array();
|
| 1915 |
+
foreach($subElements as $node) {
|
| 1916 |
+
// search first DOMElement sibling
|
| 1917 |
+
$test = $node->nextSibling;
|
| 1918 |
+
while($test && ! ($test instanceof DOMELEMENT))
|
| 1919 |
+
$test = $test->nextSibling;
|
| 1920 |
+
if ($test && $this->is($subSelector, $test))
|
| 1921 |
+
$this->elements[] = $test;
|
| 1922 |
+
}
|
| 1923 |
+
if (! $this->length() )
|
| 1924 |
+
break;
|
| 1925 |
+
// PSEUDO CLASSES
|
| 1926 |
+
} else if ($s[0] == ':') {
|
| 1927 |
+
// TODO optimization for :first :last
|
| 1928 |
+
if ($XQuery) {
|
| 1929 |
+
$this->runQuery($XQuery);
|
| 1930 |
+
$XQuery = '';
|
| 1931 |
+
}
|
| 1932 |
+
if (! $this->length())
|
| 1933 |
+
break;
|
| 1934 |
+
$this->pseudoClasses($s);
|
| 1935 |
+
if (! $this->length())
|
| 1936 |
+
break;
|
| 1937 |
+
// DIRECT DESCENDANDS
|
| 1938 |
+
} else if ($s == '>') {
|
| 1939 |
+
$XQuery .= '/';
|
| 1940 |
+
$delimiterBefore = 2;
|
| 1941 |
+
// ALL DESCENDANDS
|
| 1942 |
+
} else if ($s == ' ') {
|
| 1943 |
+
$XQuery .= '//';
|
| 1944 |
+
$delimiterBefore = 2;
|
| 1945 |
+
// ERRORS
|
| 1946 |
+
} else {
|
| 1947 |
+
phpQuery::debug("Unrecognized token '$s'");
|
| 1948 |
+
}
|
| 1949 |
+
$delimiterBefore = $delimiterBefore === 2;
|
| 1950 |
+
}
|
| 1951 |
+
// run query if any
|
| 1952 |
+
if ($XQuery && $XQuery != '//') {
|
| 1953 |
+
$this->runQuery($XQuery);
|
| 1954 |
+
$XQuery = '';
|
| 1955 |
+
}
|
| 1956 |
+
foreach($this->elements as $node)
|
| 1957 |
+
if (! $this->elementsContainsNode($node, $stack))
|
| 1958 |
+
$stack[] = $node;
|
| 1959 |
+
}
|
| 1960 |
+
$this->elements = $stack;
|
| 1961 |
+
return $this->newInstance();
|
| 1962 |
+
}
|
| 1963 |
+
/**
|
| 1964 |
+
* @todo create API for classes with pseudoselectors
|
| 1965 |
+
* @access private
|
| 1966 |
+
*/
|
| 1967 |
+
protected function pseudoClasses($class) {
|
| 1968 |
+
// TODO clean args parsing ?
|
| 1969 |
+
$class = ltrim($class, ':');
|
| 1970 |
+
$haveArgs = mb_strpos($class, '(');
|
| 1971 |
+
if ($haveArgs !== false) {
|
| 1972 |
+
$args = substr($class, $haveArgs+1, -1);
|
| 1973 |
+
$class = substr($class, 0, $haveArgs);
|
| 1974 |
+
}
|
| 1975 |
+
switch($class) {
|
| 1976 |
+
case 'even':
|
| 1977 |
+
case 'odd':
|
| 1978 |
+
$stack = array();
|
| 1979 |
+
foreach($this->elements as $i => $node) {
|
| 1980 |
+
if ($class == 'even' && ($i%2) == 0)
|
| 1981 |
+
$stack[] = $node;
|
| 1982 |
+
else if ( $class == 'odd' && $i % 2 )
|
| 1983 |
+
$stack[] = $node;
|
| 1984 |
+
}
|
| 1985 |
+
$this->elements = $stack;
|
| 1986 |
+
break;
|
| 1987 |
+
case 'eq':
|
| 1988 |
+
$k = intval($args);
|
| 1989 |
+
$this->elements = isset( $this->elements[$k] )
|
| 1990 |
+
? array( $this->elements[$k] )
|
| 1991 |
+
: array();
|
| 1992 |
+
break;
|
| 1993 |
+
case 'gt':
|
| 1994 |
+
$this->elements = array_slice($this->elements, $args+1);
|
| 1995 |
+
break;
|
| 1996 |
+
case 'lt':
|
| 1997 |
+
$this->elements = array_slice($this->elements, 0, $args+1);
|
| 1998 |
+
break;
|
| 1999 |
+
case 'first':
|
| 2000 |
+
if (isset($this->elements[0]))
|
| 2001 |
+
$this->elements = array($this->elements[0]);
|
| 2002 |
+
break;
|
| 2003 |
+
case 'last':
|
| 2004 |
+
if ($this->elements)
|
| 2005 |
+
$this->elements = array($this->elements[count($this->elements)-1]);
|
| 2006 |
+
break;
|
| 2007 |
+
/*case 'parent':
|
| 2008 |
+
$stack = array();
|
| 2009 |
+
foreach($this->elements as $node) {
|
| 2010 |
+
if ( $node->childNodes->length )
|
| 2011 |
+
$stack[] = $node;
|
| 2012 |
+
}
|
| 2013 |
+
$this->elements = $stack;
|
| 2014 |
+
break;*/
|
| 2015 |
+
case 'contains':
|
| 2016 |
+
$text = trim($args, "\"'");
|
| 2017 |
+
$stack = array();
|
| 2018 |
+
foreach($this->elements as $node) {
|
| 2019 |
+
if (mb_stripos($node->textContent, $text) === false)
|
| 2020 |
+
continue;
|
| 2021 |
+
$stack[] = $node;
|
| 2022 |
+
}
|
| 2023 |
+
$this->elements = $stack;
|
| 2024 |
+
break;
|
| 2025 |
+
case 'not':
|
| 2026 |
+
$selector = self::unQuote($args);
|
| 2027 |
+
$this->elements = $this->not($selector)->stack();
|
| 2028 |
+
break;
|
| 2029 |
+
case 'slice':
|
| 2030 |
+
// TODO jQuery difference ?
|
| 2031 |
+
$args = explode(',',
|
| 2032 |
+
str_replace(', ', ',', trim($args, "\"'"))
|
| 2033 |
+
);
|
| 2034 |
+
$start = $args[0];
|
| 2035 |
+
$end = isset($args[1])
|
| 2036 |
+
? $args[1]
|
| 2037 |
+
: null;
|
| 2038 |
+
if ($end > 0)
|
| 2039 |
+
$end = $end-$start;
|
| 2040 |
+
$this->elements = array_slice($this->elements, $start, $end);
|
| 2041 |
+
break;
|
| 2042 |
+
case 'has':
|
| 2043 |
+
$selector = trim($args, "\"'");
|
| 2044 |
+
$stack = array();
|
| 2045 |
+
foreach($this->stack(1) as $el) {
|
| 2046 |
+
if ($this->find($selector, $el, true)->length)
|
| 2047 |
+
$stack[] = $el;
|
| 2048 |
+
}
|
| 2049 |
+
$this->elements = $stack;
|
| 2050 |
+
break;
|
| 2051 |
+
case 'submit':
|
| 2052 |
+
case 'reset':
|
| 2053 |
+
$this->elements = phpQuery::merge(
|
| 2054 |
+
$this->map(array($this, 'is'),
|
| 2055 |
+
"input[type=$class]", new CallbackParam()
|
| 2056 |
+
),
|
| 2057 |
+
$this->map(array($this, 'is'),
|
| 2058 |
+
"button[type=$class]", new CallbackParam()
|
| 2059 |
+
)
|
| 2060 |
+
);
|
| 2061 |
+
break;
|
| 2062 |
+
// $stack = array();
|
| 2063 |
+
// foreach($this->elements as $node)
|
| 2064 |
+
// if ($node->is('input[type=submit]') || $node->is('button[type=submit]'))
|
| 2065 |
+
// $stack[] = $el;
|
| 2066 |
+
// $this->elements = $stack;
|
| 2067 |
+
case 'input':
|
| 2068 |
+
$this->elements = $this->map(
|
| 2069 |
+
array($this, 'is'),
|
| 2070 |
+
'input', new CallbackParam()
|
| 2071 |
+
)->elements;
|
| 2072 |
+
break;
|
| 2073 |
+
case 'password':
|
| 2074 |
+
case 'checkbox':
|
| 2075 |
+
case 'radio':
|
| 2076 |
+
case 'hidden':
|
| 2077 |
+
case 'image':
|
| 2078 |
+
case 'file':
|
| 2079 |
+
$this->elements = $this->map(
|
| 2080 |
+
array($this, 'is'),
|
| 2081 |
+
"input[type=$class]", new CallbackParam()
|
| 2082 |
+
)->elements;
|
| 2083 |
+
break;
|
| 2084 |
+
case 'parent':
|
| 2085 |
+
$this->elements = $this->map(
|
| 2086 |
+
create_function('$node', '
|
| 2087 |
+
return $node instanceof DOMELEMENT && $node->childNodes->length
|
| 2088 |
+
? $node : null;')
|
| 2089 |
+
)->elements;
|
| 2090 |
+
break;
|
| 2091 |
+
case 'empty':
|
| 2092 |
+
$this->elements = $this->map(
|
| 2093 |
+
create_function('$node', '
|
| 2094 |
+
return $node instanceof DOMELEMENT && $node->childNodes->length
|
| 2095 |
+
? null : $node;')
|
| 2096 |
+
)->elements;
|
| 2097 |
+
break;
|
| 2098 |
+
case 'disabled':
|
| 2099 |
+
case 'selected':
|
| 2100 |
+
case 'checked':
|
| 2101 |
+
$this->elements = $this->map(
|
| 2102 |
+
array($this, 'is'),
|
| 2103 |
+
"[$class]", new CallbackParam()
|
| 2104 |
+
)->elements;
|
| 2105 |
+
break;
|
| 2106 |
+
case 'enabled':
|
| 2107 |
+
$this->elements = $this->map(
|
| 2108 |
+
create_function('$node', '
|
| 2109 |
+
return pq($node)->not(":disabled") ? $node : null;')
|
| 2110 |
+
)->elements;
|
| 2111 |
+
break;
|
| 2112 |
+
case 'header':
|
| 2113 |
+
$this->elements = $this->map(
|
| 2114 |
+
create_function('$node',
|
| 2115 |
+
'$isHeader = isset($node->tagName) && in_array($node->tagName, array(
|
| 2116 |
+
"h1", "h2", "h3", "h4", "h5", "h6", "h7"
|
| 2117 |
+
));
|
| 2118 |
+
return $isHeader
|
| 2119 |
+
? $node
|
| 2120 |
+
: null;')
|
| 2121 |
+
)->elements;
|
| 2122 |
+
// $this->elements = $this->map(
|
| 2123 |
+
// create_function('$node', '$node = pq($node);
|
| 2124 |
+
// return $node->is("h1")
|
| 2125 |
+
// || $node->is("h2")
|
| 2126 |
+
// || $node->is("h3")
|
| 2127 |
+
// || $node->is("h4")
|
| 2128 |
+
// || $node->is("h5")
|
| 2129 |
+
// || $node->is("h6")
|
| 2130 |
+
// || $node->is("h7")
|
| 2131 |
+
// ? $node
|
| 2132 |
+
// : null;')
|
| 2133 |
+
// )->elements;
|
| 2134 |
+
break;
|
| 2135 |
+
case 'only-child':
|
| 2136 |
+
$this->elements = $this->map(
|
| 2137 |
+
create_function('$node',
|
| 2138 |
+
'return pq($node)->siblings()->size() == 0 ? $node : null;')
|
| 2139 |
+
)->elements;
|
| 2140 |
+
break;
|
| 2141 |
+
case 'first-child':
|
| 2142 |
+
$this->elements = $this->map(
|
| 2143 |
+
create_function('$node', 'return pq($node)->prevAll()->size() == 0 ? $node : null;')
|
| 2144 |
+
)->elements;
|
| 2145 |
+
break;
|
| 2146 |
+
case 'last-child':
|
| 2147 |
+
$this->elements = $this->map(
|
| 2148 |
+
create_function('$node', 'return pq($node)->nextAll()->size() == 0 ? $node : null;')
|
| 2149 |
+
)->elements;
|
| 2150 |
+
break;
|
| 2151 |
+
case 'nth-child':
|
| 2152 |
+
$param = trim($args, "\"'");
|
| 2153 |
+
if (! $param)
|
| 2154 |
+
break;
|
| 2155 |
+
// nth-child(n+b) to nth-child(1n+b)
|
| 2156 |
+
if ($param{0} == 'n')
|
| 2157 |
+
$param = '1'.$param;
|
| 2158 |
+
// :nth-child(index/even/odd/equation)
|
| 2159 |
+
if ($param == 'even' || $param == 'odd')
|
| 2160 |
+
$mapped = $this->map(
|
| 2161 |
+
create_function('$node, $param',
|
| 2162 |
+
'$index = pq($node)->prevAll()->size()+1;
|
| 2163 |
+
if ($param == "even" && ($index%2) == 0)
|
| 2164 |
+
return $node;
|
| 2165 |
+
else if ($param == "odd" && $index%2 == 1)
|
| 2166 |
+
return $node;
|
| 2167 |
+
else
|
| 2168 |
+
return null;'),
|
| 2169 |
+
new CallbackParam(), $param
|
| 2170 |
+
);
|
| 2171 |
+
else if (mb_strlen($param) > 1 && $param{1} == 'n')
|
| 2172 |
+
// an+b
|
| 2173 |
+
$mapped = $this->map(
|
| 2174 |
+
create_function('$node, $param',
|
| 2175 |
+
'$prevs = pq($node)->prevAll()->size();
|
| 2176 |
+
$index = 1+$prevs;
|
| 2177 |
+
$b = mb_strlen($param) > 3
|
| 2178 |
+
? $param{3}
|
| 2179 |
+
: 0;
|
| 2180 |
+
$a = $param{0};
|
| 2181 |
+
if ($b && $param{2} == "-")
|
| 2182 |
+
$b = -$b;
|
| 2183 |
+
if ($a > 0) {
|
| 2184 |
+
return ($index-$b)%$a == 0
|
| 2185 |
+
? $node
|
| 2186 |
+
: null;
|
| 2187 |
+
phpQuery::debug($a."*".floor($index/$a)."+$b-1 == ".($a*floor($index/$a)+$b-1)." ?= $prevs");
|
| 2188 |
+
return $a*floor($index/$a)+$b-1 == $prevs
|
| 2189 |
+
? $node
|
| 2190 |
+
: null;
|
| 2191 |
+
} else if ($a == 0)
|
| 2192 |
+
return $index == $b
|
| 2193 |
+
? $node
|
| 2194 |
+
: null;
|
| 2195 |
+
else
|
| 2196 |
+
// negative value
|
| 2197 |
+
return $index <= $b
|
| 2198 |
+
? $node
|
| 2199 |
+
: null;
|
| 2200 |
+
// if (! $b)
|
| 2201 |
+
// return $index%$a == 0
|
| 2202 |
+
// ? $node
|
| 2203 |
+
// : null;
|
| 2204 |
+
// else
|
| 2205 |
+
// return ($index-$b)%$a == 0
|
| 2206 |
+
// ? $node
|
| 2207 |
+
// : null;
|
| 2208 |
+
'),
|
| 2209 |
+
new CallbackParam(), $param
|
| 2210 |
+
);
|
| 2211 |
+
else
|
| 2212 |
+
// index
|
| 2213 |
+
$mapped = $this->map(
|
| 2214 |
+
create_function('$node, $index',
|
| 2215 |
+
'$prevs = pq($node)->prevAll()->size();
|
| 2216 |
+
if ($prevs && $prevs == $index-1)
|
| 2217 |
+
return $node;
|
| 2218 |
+
else if (! $prevs && $index == 1)
|
| 2219 |
+
return $node;
|
| 2220 |
+
else
|
| 2221 |
+
return null;'),
|
| 2222 |
+
new CallbackParam(), $param
|
| 2223 |
+
);
|
| 2224 |
+
$this->elements = $mapped->elements;
|
| 2225 |
+
break;
|
| 2226 |
+
default:
|
| 2227 |
+
$this->debug("Unknown pseudoclass '{$class}', skipping...");
|
| 2228 |
+
}
|
| 2229 |
+
}
|
| 2230 |
+
/**
|
| 2231 |
+
* @access private
|
| 2232 |
+
*/
|
| 2233 |
+
protected function __pseudoClassParam($paramsString) {
|
| 2234 |
+
// TODO;
|
| 2235 |
+
}
|
| 2236 |
+
/**
|
| 2237 |
+
* Enter description here...
|
| 2238 |
+
*
|
| 2239 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2240 |
+
*/
|
| 2241 |
+
public function is($selector, $nodes = null) {
|
| 2242 |
+
phpQuery::debug(array("Is:", $selector));
|
| 2243 |
+
if (! $selector)
|
| 2244 |
+
return false;
|
| 2245 |
+
$oldStack = $this->elements;
|
| 2246 |
+
$returnArray = false;
|
| 2247 |
+
if ($nodes && is_array($nodes)) {
|
| 2248 |
+
$this->elements = $nodes;
|
| 2249 |
+
} else if ($nodes)
|
| 2250 |
+
$this->elements = array($nodes);
|
| 2251 |
+
$this->filter($selector, true);
|
| 2252 |
+
$stack = $this->elements;
|
| 2253 |
+
$this->elements = $oldStack;
|
| 2254 |
+
if ($nodes)
|
| 2255 |
+
return $stack ? $stack : null;
|
| 2256 |
+
return (bool)count($stack);
|
| 2257 |
+
}
|
| 2258 |
+
/**
|
| 2259 |
+
* Enter description here...
|
| 2260 |
+
* jQuery difference.
|
| 2261 |
+
*
|
| 2262 |
+
* Callback:
|
| 2263 |
+
* - $index int
|
| 2264 |
+
* - $node DOMNode
|
| 2265 |
+
*
|
| 2266 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2267 |
+
* @link http://docs.jquery.com/Traversing/filter
|
| 2268 |
+
*/
|
| 2269 |
+
public function filterCallback($callback, $_skipHistory = false) {
|
| 2270 |
+
if (! $_skipHistory) {
|
| 2271 |
+
$this->elementsBackup = $this->elements;
|
| 2272 |
+
$this->debug("Filtering by callback");
|
| 2273 |
+
}
|
| 2274 |
+
$newStack = array();
|
| 2275 |
+
foreach($this->elements as $index => $node) {
|
| 2276 |
+
$result = phpQuery::callbackRun($callback, array($index, $node));
|
| 2277 |
+
if (is_null($result) || (! is_null($result) && $result))
|
| 2278 |
+
$newStack[] = $node;
|
| 2279 |
+
}
|
| 2280 |
+
$this->elements = $newStack;
|
| 2281 |
+
return $_skipHistory
|
| 2282 |
+
? $this
|
| 2283 |
+
: $this->newInstance();
|
| 2284 |
+
}
|
| 2285 |
+
/**
|
| 2286 |
+
* Enter description here...
|
| 2287 |
+
*
|
| 2288 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2289 |
+
* @link http://docs.jquery.com/Traversing/filter
|
| 2290 |
+
*/
|
| 2291 |
+
public function filter($selectors, $_skipHistory = false) {
|
| 2292 |
+
if ($selectors instanceof Callback OR $selectors instanceof Closure)
|
| 2293 |
+
return $this->filterCallback($selectors, $_skipHistory);
|
| 2294 |
+
if (! $_skipHistory)
|
| 2295 |
+
$this->elementsBackup = $this->elements;
|
| 2296 |
+
$notSimpleSelector = array(' ', '>', '~', '+', '/');
|
| 2297 |
+
if (! is_array($selectors))
|
| 2298 |
+
$selectors = $this->parseSelector($selectors);
|
| 2299 |
+
if (! $_skipHistory)
|
| 2300 |
+
$this->debug(array("Filtering:", $selectors));
|
| 2301 |
+
$finalStack = array();
|
| 2302 |
+
foreach($selectors as $selector) {
|
| 2303 |
+
$stack = array();
|
| 2304 |
+
if (! $selector)
|
| 2305 |
+
break;
|
| 2306 |
+
// avoid first space or /
|
| 2307 |
+
if (in_array($selector[0], $notSimpleSelector))
|
| 2308 |
+
$selector = array_slice($selector, 1);
|
| 2309 |
+
// PER NODE selector chunks
|
| 2310 |
+
foreach($this->stack() as $node) {
|
| 2311 |
+
$break = false;
|
| 2312 |
+
foreach($selector as $s) {
|
| 2313 |
+
if (!($node instanceof DOMELEMENT)) {
|
| 2314 |
+
// all besides DOMElement
|
| 2315 |
+
if ( $s[0] == '[') {
|
| 2316 |
+
$attr = trim($s, '[]');
|
| 2317 |
+
if ( mb_strpos($attr, '=')) {
|
| 2318 |
+
list( $attr, $val ) = explode('=', $attr);
|
| 2319 |
+
if ($attr == 'nodeType' && $node->nodeType != $val)
|
| 2320 |
+
$break = true;
|
| 2321 |
+
}
|
| 2322 |
+
} else
|
| 2323 |
+
$break = true;
|
| 2324 |
+
} else {
|
| 2325 |
+
// DOMElement only
|
| 2326 |
+
// ID
|
| 2327 |
+
if ( $s[0] == '#') {
|
| 2328 |
+
if ( $node->getAttribute('id') != substr($s, 1) )
|
| 2329 |
+
$break = true;
|
| 2330 |
+
// CLASSES
|
| 2331 |
+
} else if ( $s[0] == '.') {
|
| 2332 |
+
if (! $this->matchClasses( $s, $node ) )
|
| 2333 |
+
$break = true;
|
| 2334 |
+
// ATTRS
|
| 2335 |
+
} else if ( $s[0] == '[') {
|
| 2336 |
+
// strip side brackets
|
| 2337 |
+
$attr = trim($s, '[]');
|
| 2338 |
+
if (mb_strpos($attr, '=')) {
|
| 2339 |
+
list($attr, $val) = explode('=', $attr);
|
| 2340 |
+
$val = self::unQuote($val);
|
| 2341 |
+
if ($attr == 'nodeType') {
|
| 2342 |
+
if ($val != $node->nodeType)
|
| 2343 |
+
$break = true;
|
| 2344 |
+
} else if ($this->isRegexp($attr)) {
|
| 2345 |
+
$val = extension_loaded('mbstring') && phpQuery::$mbstringSupport
|
| 2346 |
+
? quotemeta(trim($val, '"\''))
|
| 2347 |
+
: preg_quote(trim($val, '"\''), '@');
|
| 2348 |
+
// switch last character
|
| 2349 |
+
switch( substr($attr, -1)) {
|
| 2350 |
+
// quotemeta used insted of preg_quote
|
| 2351 |
+
// http://code.google.com/p/phpquery/issues/detail?id=76
|
| 2352 |
+
case '^':
|
| 2353 |
+
$pattern = '^'.$val;
|
| 2354 |
+
break;
|
| 2355 |
+
case '*':
|
| 2356 |
+
$pattern = '.*'.$val.'.*';
|
| 2357 |
+
break;
|
| 2358 |
+
case '$':
|
| 2359 |
+
$pattern = '.*'.$val.'$';
|
| 2360 |
+
break;
|
| 2361 |
+
}
|
| 2362 |
+
// cut last character
|
| 2363 |
+
$attr = substr($attr, 0, -1);
|
| 2364 |
+
$isMatch = extension_loaded('mbstring') && phpQuery::$mbstringSupport
|
| 2365 |
+
? mb_ereg_match($pattern, $node->getAttribute($attr))
|
| 2366 |
+
: preg_match("@{$pattern}@", $node->getAttribute($attr));
|
| 2367 |
+
if (! $isMatch)
|
| 2368 |
+
$break = true;
|
| 2369 |
+
} else if ($node->getAttribute($attr) != $val)
|
| 2370 |
+
$break = true;
|
| 2371 |
+
} else if (! $node->hasAttribute($attr))
|
| 2372 |
+
$break = true;
|
| 2373 |
+
// PSEUDO CLASSES
|
| 2374 |
+
} else if ( $s[0] == ':') {
|
| 2375 |
+
// skip
|
| 2376 |
+
// TAG
|
| 2377 |
+
} else if (trim($s)) {
|
| 2378 |
+
if ($s != '*') {
|
| 2379 |
+
// TODO namespaces
|
| 2380 |
+
if (isset($node->tagName)) {
|
| 2381 |
+
if ($node->tagName != $s)
|
| 2382 |
+
$break = true;
|
| 2383 |
+
} else if ($s == 'html' && ! $this->isRoot($node))
|
| 2384 |
+
$break = true;
|
| 2385 |
+
}
|
| 2386 |
+
// AVOID NON-SIMPLE SELECTORS
|
| 2387 |
+
} else if (in_array($s, $notSimpleSelector)) {
|
| 2388 |
+
$break = true;
|
| 2389 |
+
$this->debug(array('Skipping non simple selector', $selector));
|
| 2390 |
+
}
|
| 2391 |
+
}
|
| 2392 |
+
if ($break)
|
| 2393 |
+
break;
|
| 2394 |
+
}
|
| 2395 |
+
// if element passed all chunks of selector - add it to new stack
|
| 2396 |
+
if (! $break )
|
| 2397 |
+
$stack[] = $node;
|
| 2398 |
+
}
|
| 2399 |
+
$tmpStack = $this->elements;
|
| 2400 |
+
$this->elements = $stack;
|
| 2401 |
+
// PER ALL NODES selector chunks
|
| 2402 |
+
foreach($selector as $s)
|
| 2403 |
+
// PSEUDO CLASSES
|
| 2404 |
+
if ($s[0] == ':')
|
| 2405 |
+
$this->pseudoClasses($s);
|
| 2406 |
+
foreach($this->elements as $node)
|
| 2407 |
+
// XXX it should be merged without duplicates
|
| 2408 |
+
// but jQuery doesnt do that
|
| 2409 |
+
$finalStack[] = $node;
|
| 2410 |
+
$this->elements = $tmpStack;
|
| 2411 |
+
}
|
| 2412 |
+
$this->elements = $finalStack;
|
| 2413 |
+
if ($_skipHistory) {
|
| 2414 |
+
return $this;
|
| 2415 |
+
} else {
|
| 2416 |
+
$this->debug("Stack length after filter(): ".count($finalStack));
|
| 2417 |
+
return $this->newInstance();
|
| 2418 |
+
}
|
| 2419 |
+
}
|
| 2420 |
+
/**
|
| 2421 |
+
*
|
| 2422 |
+
* @param $value
|
| 2423 |
+
* @return unknown_type
|
| 2424 |
+
* @TODO implement in all methods using passed parameters
|
| 2425 |
+
*/
|
| 2426 |
+
protected static function unQuote($value) {
|
| 2427 |
+
return $value[0] == '\'' || $value[0] == '"'
|
| 2428 |
+
? substr($value, 1, -1)
|
| 2429 |
+
: $value;
|
| 2430 |
+
}
|
| 2431 |
+
/**
|
| 2432 |
+
* Enter description here...
|
| 2433 |
+
*
|
| 2434 |
+
* @link http://docs.jquery.com/Ajax/load
|
| 2435 |
+
* @return phpQuery|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2436 |
+
* @todo Support $selector
|
| 2437 |
+
*/
|
| 2438 |
+
public function load($url, $data = null, $callback = null) {
|
| 2439 |
+
if ($data && ! is_array($data)) {
|
| 2440 |
+
$callback = $data;
|
| 2441 |
+
$data = null;
|
| 2442 |
+
}
|
| 2443 |
+
if (mb_strpos($url, ' ') !== false) {
|
| 2444 |
+
$matches = null;
|
| 2445 |
+
if (extension_loaded('mbstring') && phpQuery::$mbstringSupport)
|
| 2446 |
+
mb_ereg('^([^ ]+) (.*)$', $url, $matches);
|
| 2447 |
+
else
|
| 2448 |
+
preg_match('^([^ ]+) (.*)$', $url, $matches);
|
| 2449 |
+
$url = $matches[1];
|
| 2450 |
+
$selector = $matches[2];
|
| 2451 |
+
// FIXME this sucks, pass as callback param
|
| 2452 |
+
$this->_loadSelector = $selector;
|
| 2453 |
+
}
|
| 2454 |
+
$ajax = array(
|
| 2455 |
+
'url' => $url,
|
| 2456 |
+
'type' => $data ? 'POST' : 'GET',
|
| 2457 |
+
'data' => $data,
|
| 2458 |
+
'complete' => $callback,
|
| 2459 |
+
'success' => array($this, '__loadSuccess')
|
| 2460 |
+
);
|
| 2461 |
+
phpQuery::ajax($ajax);
|
| 2462 |
+
return $this;
|
| 2463 |
+
}
|
| 2464 |
+
/**
|
| 2465 |
+
* @access private
|
| 2466 |
+
* @param $html
|
| 2467 |
+
* @return unknown_type
|
| 2468 |
+
*/
|
| 2469 |
+
public function __loadSuccess($html) {
|
| 2470 |
+
if ($this->_loadSelector) {
|
| 2471 |
+
$html = phpQuery::newDocument($html)->find($this->_loadSelector);
|
| 2472 |
+
unset($this->_loadSelector);
|
| 2473 |
+
}
|
| 2474 |
+
foreach($this->stack(1) as $node) {
|
| 2475 |
+
phpQuery::pq($node, $this->getDocumentID())
|
| 2476 |
+
->markup($html);
|
| 2477 |
+
}
|
| 2478 |
+
}
|
| 2479 |
+
/**
|
| 2480 |
+
* Enter description here...
|
| 2481 |
+
*
|
| 2482 |
+
* @return phpQuery|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2483 |
+
* @todo
|
| 2484 |
+
*/
|
| 2485 |
+
public function css() {
|
| 2486 |
+
// TODO
|
| 2487 |
+
return $this;
|
| 2488 |
+
}
|
| 2489 |
+
/**
|
| 2490 |
+
* @todo
|
| 2491 |
+
*
|
| 2492 |
+
*/
|
| 2493 |
+
public function show(){
|
| 2494 |
+
// TODO
|
| 2495 |
+
return $this;
|
| 2496 |
+
}
|
| 2497 |
+
/**
|
| 2498 |
+
* @todo
|
| 2499 |
+
*
|
| 2500 |
+
*/
|
| 2501 |
+
public function hide(){
|
| 2502 |
+
// TODO
|
| 2503 |
+
return $this;
|
| 2504 |
+
}
|
| 2505 |
+
/**
|
| 2506 |
+
* Trigger a type of event on every matched element.
|
| 2507 |
+
*
|
| 2508 |
+
* @param unknown_type $type
|
| 2509 |
+
* @param unknown_type $data
|
| 2510 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2511 |
+
* @TODO support more than event in $type (space-separated)
|
| 2512 |
+
*/
|
| 2513 |
+
public function trigger($type, $data = array()) {
|
| 2514 |
+
foreach($this->elements as $node)
|
| 2515 |
+
phpQueryEvents::trigger($this->getDocumentID(), $type, $data, $node);
|
| 2516 |
+
return $this;
|
| 2517 |
+
}
|
| 2518 |
+
/**
|
| 2519 |
+
* This particular method triggers all bound event handlers on an element (for a specific event type) WITHOUT executing the browsers default actions.
|
| 2520 |
+
*
|
| 2521 |
+
* @param unknown_type $type
|
| 2522 |
+
* @param unknown_type $data
|
| 2523 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2524 |
+
* @TODO
|
| 2525 |
+
*/
|
| 2526 |
+
public function triggerHandler($type, $data = array()) {
|
| 2527 |
+
// TODO;
|
| 2528 |
+
}
|
| 2529 |
+
/**
|
| 2530 |
+
* Binds a handler to one or more events (like click) for each matched element.
|
| 2531 |
+
* Can also bind custom events.
|
| 2532 |
+
*
|
| 2533 |
+
* @param unknown_type $type
|
| 2534 |
+
* @param unknown_type $data Optional
|
| 2535 |
+
* @param unknown_type $callback
|
| 2536 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2537 |
+
* @TODO support '!' (exclusive) events
|
| 2538 |
+
* @TODO support more than event in $type (space-separated)
|
| 2539 |
+
*/
|
| 2540 |
+
public function bind($type, $data, $callback = null) {
|
| 2541 |
+
// TODO check if $data is callable, not using is_callable
|
| 2542 |
+
if (! isset($callback)) {
|
| 2543 |
+
$callback = $data;
|
| 2544 |
+
$data = null;
|
| 2545 |
+
}
|
| 2546 |
+
foreach($this->elements as $node)
|
| 2547 |
+
phpQueryEvents::add($this->getDocumentID(), $node, $type, $data, $callback);
|
| 2548 |
+
return $this;
|
| 2549 |
+
}
|
| 2550 |
+
/**
|
| 2551 |
+
* Enter description here...
|
| 2552 |
+
*
|
| 2553 |
+
* @param unknown_type $type
|
| 2554 |
+
* @param unknown_type $callback
|
| 2555 |
+
* @return unknown
|
| 2556 |
+
* @TODO namespace events
|
| 2557 |
+
* @TODO support more than event in $type (space-separated)
|
| 2558 |
+
*/
|
| 2559 |
+
public function unbind($type = null, $callback = null) {
|
| 2560 |
+
foreach($this->elements as $node)
|
| 2561 |
+
phpQueryEvents::remove($this->getDocumentID(), $node, $type, $callback);
|
| 2562 |
+
return $this;
|
| 2563 |
+
}
|
| 2564 |
+
/**
|
| 2565 |
+
* Enter description here...
|
| 2566 |
+
*
|
| 2567 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2568 |
+
*/
|
| 2569 |
+
public function change($callback = null) {
|
| 2570 |
+
if ($callback)
|
| 2571 |
+
return $this->bind('change', $callback);
|
| 2572 |
+
return $this->trigger('change');
|
| 2573 |
+
}
|
| 2574 |
+
/**
|
| 2575 |
+
* Enter description here...
|
| 2576 |
+
*
|
| 2577 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2578 |
+
*/
|
| 2579 |
+
public function submit($callback = null) {
|
| 2580 |
+
if ($callback)
|
| 2581 |
+
return $this->bind('submit', $callback);
|
| 2582 |
+
return $this->trigger('submit');
|
| 2583 |
+
}
|
| 2584 |
+
/**
|
| 2585 |
+
* Enter description here...
|
| 2586 |
+
*
|
| 2587 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2588 |
+
*/
|
| 2589 |
+
public function click($callback = null) {
|
| 2590 |
+
if ($callback)
|
| 2591 |
+
return $this->bind('click', $callback);
|
| 2592 |
+
return $this->trigger('click');
|
| 2593 |
+
}
|
| 2594 |
+
/**
|
| 2595 |
+
* Enter description here...
|
| 2596 |
+
*
|
| 2597 |
+
* @param String|phpQuery
|
| 2598 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2599 |
+
*/
|
| 2600 |
+
public function wrapAllOld($wrapper) {
|
| 2601 |
+
$wrapper = pq($wrapper)->_clone();
|
| 2602 |
+
if (! $wrapper->length() || ! $this->length() )
|
| 2603 |
+
return $this;
|
| 2604 |
+
$wrapper->insertBefore($this->elements[0]);
|
| 2605 |
+
$deepest = $wrapper->elements[0];
|
| 2606 |
+
while($deepest->firstChild && $deepest->firstChild instanceof DOMELEMENT)
|
| 2607 |
+
$deepest = $deepest->firstChild;
|
| 2608 |
+
pq($deepest)->append($this);
|
| 2609 |
+
return $this;
|
| 2610 |
+
}
|
| 2611 |
+
/**
|
| 2612 |
+
* Enter description here...
|
| 2613 |
+
*
|
| 2614 |
+
* TODO testme...
|
| 2615 |
+
* @param String|phpQuery
|
| 2616 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2617 |
+
*/
|
| 2618 |
+
public function wrapAll($wrapper) {
|
| 2619 |
+
if (! $this->length())
|
| 2620 |
+
return $this;
|
| 2621 |
+
return phpQuery::pq($wrapper, $this->getDocumentID())
|
| 2622 |
+
->clone()
|
| 2623 |
+
->insertBefore($this->get(0))
|
| 2624 |
+
->map(array($this, '___wrapAllCallback'))
|
| 2625 |
+
->append($this);
|
| 2626 |
+
}
|
| 2627 |
+
/**
|
| 2628 |
+
*
|
| 2629 |
+
* @param $node
|
| 2630 |
+
* @return unknown_type
|
| 2631 |
+
* @access private
|
| 2632 |
+
*/
|
| 2633 |
+
public function ___wrapAllCallback($node) {
|
| 2634 |
+
$deepest = $node;
|
| 2635 |
+
while($deepest->firstChild && $deepest->firstChild instanceof DOMELEMENT)
|
| 2636 |
+
$deepest = $deepest->firstChild;
|
| 2637 |
+
return $deepest;
|
| 2638 |
+
}
|
| 2639 |
+
/**
|
| 2640 |
+
* Enter description here...
|
| 2641 |
+
* NON JQUERY METHOD
|
| 2642 |
+
*
|
| 2643 |
+
* @param String|phpQuery
|
| 2644 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2645 |
+
*/
|
| 2646 |
+
public function wrapAllPHP($codeBefore, $codeAfter) {
|
| 2647 |
+
return $this
|
| 2648 |
+
->slice(0, 1)
|
| 2649 |
+
->beforePHP($codeBefore)
|
| 2650 |
+
->end()
|
| 2651 |
+
->slice(-1)
|
| 2652 |
+
->afterPHP($codeAfter)
|
| 2653 |
+
->end();
|
| 2654 |
+
}
|
| 2655 |
+
/**
|
| 2656 |
+
* Enter description here...
|
| 2657 |
+
*
|
| 2658 |
+
* @param String|phpQuery
|
| 2659 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2660 |
+
*/
|
| 2661 |
+
public function wrap($wrapper) {
|
| 2662 |
+
foreach($this->stack() as $node)
|
| 2663 |
+
phpQuery::pq($node, $this->getDocumentID())->wrapAll($wrapper);
|
| 2664 |
+
return $this;
|
| 2665 |
+
}
|
| 2666 |
+
/**
|
| 2667 |
+
* Enter description here...
|
| 2668 |
+
*
|
| 2669 |
+
* @param String|phpQuery
|
| 2670 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2671 |
+
*/
|
| 2672 |
+
public function wrapPHP($codeBefore, $codeAfter) {
|
| 2673 |
+
foreach($this->stack() as $node)
|
| 2674 |
+
phpQuery::pq($node, $this->getDocumentID())->wrapAllPHP($codeBefore, $codeAfter);
|
| 2675 |
+
return $this;
|
| 2676 |
+
}
|
| 2677 |
+
/**
|
| 2678 |
+
* Enter description here...
|
| 2679 |
+
*
|
| 2680 |
+
* @param String|phpQuery
|
| 2681 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2682 |
+
*/
|
| 2683 |
+
public function wrapInner($wrapper) {
|
| 2684 |
+
foreach($this->stack() as $node)
|
| 2685 |
+
phpQuery::pq($node, $this->getDocumentID())->contents()->wrapAll($wrapper);
|
| 2686 |
+
return $this;
|
| 2687 |
+
}
|
| 2688 |
+
/**
|
| 2689 |
+
* Enter description here...
|
| 2690 |
+
*
|
| 2691 |
+
* @param String|phpQuery
|
| 2692 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2693 |
+
*/
|
| 2694 |
+
public function wrapInnerPHP($codeBefore, $codeAfter) {
|
| 2695 |
+
foreach($this->stack(1) as $node)
|
| 2696 |
+
phpQuery::pq($node, $this->getDocumentID())->contents()
|
| 2697 |
+
->wrapAllPHP($codeBefore, $codeAfter);
|
| 2698 |
+
return $this;
|
| 2699 |
+
}
|
| 2700 |
+
/**
|
| 2701 |
+
* Enter description here...
|
| 2702 |
+
*
|
| 2703 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2704 |
+
* @testme Support for text nodes
|
| 2705 |
+
*/
|
| 2706 |
+
public function contents() {
|
| 2707 |
+
$stack = array();
|
| 2708 |
+
foreach($this->stack(1) as $el) {
|
| 2709 |
+
// FIXME (fixed) http://code.google.com/p/phpquery/issues/detail?id=56
|
| 2710 |
+
// if (! isset($el->childNodes))
|
| 2711 |
+
// continue;
|
| 2712 |
+
foreach($el->childNodes as $node) {
|
| 2713 |
+
$stack[] = $node;
|
| 2714 |
+
}
|
| 2715 |
+
}
|
| 2716 |
+
return $this->newInstance($stack);
|
| 2717 |
+
}
|
| 2718 |
+
/**
|
| 2719 |
+
* Enter description here...
|
| 2720 |
+
*
|
| 2721 |
+
* jQuery difference.
|
| 2722 |
+
*
|
| 2723 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2724 |
+
*/
|
| 2725 |
+
public function contentsUnwrap() {
|
| 2726 |
+
foreach($this->stack(1) as $node) {
|
| 2727 |
+
if (! $node->parentNode )
|
| 2728 |
+
continue;
|
| 2729 |
+
$childNodes = array();
|
| 2730 |
+
// any modification in DOM tree breaks childNodes iteration, so cache them first
|
| 2731 |
+
foreach($node->childNodes as $chNode )
|
| 2732 |
+
$childNodes[] = $chNode;
|
| 2733 |
+
foreach($childNodes as $chNode )
|
| 2734 |
+
// $node->parentNode->appendChild($chNode);
|
| 2735 |
+
$node->parentNode->insertBefore($chNode, $node);
|
| 2736 |
+
$node->parentNode->removeChild($node);
|
| 2737 |
+
}
|
| 2738 |
+
return $this;
|
| 2739 |
+
}
|
| 2740 |
+
/**
|
| 2741 |
+
* Enter description here...
|
| 2742 |
+
*
|
| 2743 |
+
* jQuery difference.
|
| 2744 |
+
*/
|
| 2745 |
+
public function switchWith($markup) {
|
| 2746 |
+
$markup = pq($markup, $this->getDocumentID());
|
| 2747 |
+
$content = null;
|
| 2748 |
+
foreach($this->stack(1) as $node) {
|
| 2749 |
+
pq($node)
|
| 2750 |
+
->contents()->toReference($content)->end()
|
| 2751 |
+
->replaceWith($markup->clone()->append($content));
|
| 2752 |
+
}
|
| 2753 |
+
return $this;
|
| 2754 |
+
}
|
| 2755 |
+
/**
|
| 2756 |
+
* Enter description here...
|
| 2757 |
+
*
|
| 2758 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2759 |
+
*/
|
| 2760 |
+
public function eq($num) {
|
| 2761 |
+
$oldStack = $this->elements;
|
| 2762 |
+
$this->elementsBackup = $this->elements;
|
| 2763 |
+
$this->elements = array();
|
| 2764 |
+
if ( isset($oldStack[$num]) )
|
| 2765 |
+
$this->elements[] = $oldStack[$num];
|
| 2766 |
+
return $this->newInstance();
|
| 2767 |
+
}
|
| 2768 |
+
/**
|
| 2769 |
+
* Enter description here...
|
| 2770 |
+
*
|
| 2771 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2772 |
+
*/
|
| 2773 |
+
public function size() {
|
| 2774 |
+
return count($this->elements);
|
| 2775 |
+
}
|
| 2776 |
+
/**
|
| 2777 |
+
* Enter description here...
|
| 2778 |
+
*
|
| 2779 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2780 |
+
* @deprecated Use length as attribute
|
| 2781 |
+
*/
|
| 2782 |
+
public function length() {
|
| 2783 |
+
return $this->size();
|
| 2784 |
+
}
|
| 2785 |
+
public function count() {
|
| 2786 |
+
return $this->size();
|
| 2787 |
+
}
|
| 2788 |
+
/**
|
| 2789 |
+
* Enter description here...
|
| 2790 |
+
*
|
| 2791 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2792 |
+
* @todo $level
|
| 2793 |
+
*/
|
| 2794 |
+
public function end($level = 1) {
|
| 2795 |
+
// $this->elements = array_pop( $this->history );
|
| 2796 |
+
// return $this;
|
| 2797 |
+
// $this->previous->DOM = $this->DOM;
|
| 2798 |
+
// $this->previous->XPath = $this->XPath;
|
| 2799 |
+
return $this->previous
|
| 2800 |
+
? $this->previous
|
| 2801 |
+
: $this;
|
| 2802 |
+
}
|
| 2803 |
+
/**
|
| 2804 |
+
* Enter description here...
|
| 2805 |
+
* Normal use ->clone() .
|
| 2806 |
+
*
|
| 2807 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2808 |
+
* @access private
|
| 2809 |
+
*/
|
| 2810 |
+
public function _clone() {
|
| 2811 |
+
$newStack = array();
|
| 2812 |
+
//pr(array('copy... ', $this->whois()));
|
| 2813 |
+
//$this->dumpHistory('copy');
|
| 2814 |
+
$this->elementsBackup = $this->elements;
|
| 2815 |
+
foreach($this->elements as $node) {
|
| 2816 |
+
$newStack[] = $node->cloneNode(true);
|
| 2817 |
+
}
|
| 2818 |
+
$this->elements = $newStack;
|
| 2819 |
+
return $this->newInstance();
|
| 2820 |
+
}
|
| 2821 |
+
/**
|
| 2822 |
+
* Enter description here...
|
| 2823 |
+
*
|
| 2824 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2825 |
+
*/
|
| 2826 |
+
public function replaceWithPHP($code) {
|
| 2827 |
+
return $this->replaceWith(phpQuery::php($code));
|
| 2828 |
+
}
|
| 2829 |
+
/**
|
| 2830 |
+
* Enter description here...
|
| 2831 |
+
*
|
| 2832 |
+
* @param String|phpQuery $content
|
| 2833 |
+
* @link http://docs.jquery.com/Manipulation/replaceWith#content
|
| 2834 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2835 |
+
*/
|
| 2836 |
+
public function replaceWith($content) {
|
| 2837 |
+
return $this->after($content)->remove();
|
| 2838 |
+
}
|
| 2839 |
+
/**
|
| 2840 |
+
* Enter description here...
|
| 2841 |
+
*
|
| 2842 |
+
* @param String $selector
|
| 2843 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2844 |
+
* @todo this works ?
|
| 2845 |
+
*/
|
| 2846 |
+
public function replaceAll($selector) {
|
| 2847 |
+
foreach(phpQuery::pq($selector, $this->getDocumentID()) as $node)
|
| 2848 |
+
phpQuery::pq($node, $this->getDocumentID())
|
| 2849 |
+
->after($this->_clone())
|
| 2850 |
+
->remove();
|
| 2851 |
+
return $this;
|
| 2852 |
+
}
|
| 2853 |
+
/**
|
| 2854 |
+
* Enter description here...
|
| 2855 |
+
*
|
| 2856 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2857 |
+
*/
|
| 2858 |
+
public function remove($selector = null) {
|
| 2859 |
+
$loop = $selector
|
| 2860 |
+
? $this->filter($selector)->elements
|
| 2861 |
+
: $this->elements;
|
| 2862 |
+
foreach($loop as $node) {
|
| 2863 |
+
if (! $node->parentNode )
|
| 2864 |
+
continue;
|
| 2865 |
+
if (isset($node->tagName))
|
| 2866 |
+
$this->debug("Removing '{$node->tagName}'");
|
| 2867 |
+
$node->parentNode->removeChild($node);
|
| 2868 |
+
// Mutation event
|
| 2869 |
+
$event = new DOMEvent(array(
|
| 2870 |
+
'target' => $node,
|
| 2871 |
+
'type' => 'DOMNodeRemoved'
|
| 2872 |
+
));
|
| 2873 |
+
phpQueryEvents::trigger($this->getDocumentID(),
|
| 2874 |
+
$event->type, array($event), $node
|
| 2875 |
+
);
|
| 2876 |
+
}
|
| 2877 |
+
return $this;
|
| 2878 |
+
}
|
| 2879 |
+
protected function markupEvents($newMarkup, $oldMarkup, $node) {
|
| 2880 |
+
if ($node->tagName == 'textarea' && $newMarkup != $oldMarkup) {
|
| 2881 |
+
$event = new DOMEvent(array(
|
| 2882 |
+
'target' => $node,
|
| 2883 |
+
'type' => 'change'
|
| 2884 |
+
));
|
| 2885 |
+
phpQueryEvents::trigger($this->getDocumentID(),
|
| 2886 |
+
$event->type, array($event), $node
|
| 2887 |
+
);
|
| 2888 |
+
}
|
| 2889 |
+
}
|
| 2890 |
+
/**
|
| 2891 |
+
* jQuey difference
|
| 2892 |
+
*
|
| 2893 |
+
* @param $markup
|
| 2894 |
+
* @return unknown_type
|
| 2895 |
+
* @TODO trigger change event for textarea
|
| 2896 |
+
*/
|
| 2897 |
+
public function markup($markup = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2898 |
+
$args = func_get_args();
|
| 2899 |
+
if ($this->documentWrapper->isXML)
|
| 2900 |
+
return call_user_func_array(array($this, 'xml'), $args);
|
| 2901 |
+
else
|
| 2902 |
+
return call_user_func_array(array($this, 'html'), $args);
|
| 2903 |
+
}
|
| 2904 |
+
/**
|
| 2905 |
+
* jQuey difference
|
| 2906 |
+
*
|
| 2907 |
+
* @param $markup
|
| 2908 |
+
* @return unknown_type
|
| 2909 |
+
*/
|
| 2910 |
+
public function markupOuter($callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2911 |
+
$args = func_get_args();
|
| 2912 |
+
if ($this->documentWrapper->isXML)
|
| 2913 |
+
return call_user_func_array(array($this, 'xmlOuter'), $args);
|
| 2914 |
+
else
|
| 2915 |
+
return call_user_func_array(array($this, 'htmlOuter'), $args);
|
| 2916 |
+
}
|
| 2917 |
+
/**
|
| 2918 |
+
* Enter description here...
|
| 2919 |
+
*
|
| 2920 |
+
* @param unknown_type $html
|
| 2921 |
+
* @return string|phpQuery|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2922 |
+
* @TODO force html result
|
| 2923 |
+
*/
|
| 2924 |
+
public function html($html = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2925 |
+
if (isset($html)) {
|
| 2926 |
+
// INSERT
|
| 2927 |
+
$nodes = $this->documentWrapper->import($html);
|
| 2928 |
+
$this->empty();
|
| 2929 |
+
foreach($this->stack(1) as $alreadyAdded => $node) {
|
| 2930 |
+
// for now, limit events for textarea
|
| 2931 |
+
if (($this->isXHTML() || $this->isHTML()) && $node->tagName == 'textarea')
|
| 2932 |
+
$oldHtml = pq($node, $this->getDocumentID())->markup();
|
| 2933 |
+
foreach($nodes as $newNode) {
|
| 2934 |
+
$node->appendChild($alreadyAdded
|
| 2935 |
+
? $newNode->cloneNode(true)
|
| 2936 |
+
: $newNode
|
| 2937 |
+
);
|
| 2938 |
+
}
|
| 2939 |
+
// for now, limit events for textarea
|
| 2940 |
+
if (($this->isXHTML() || $this->isHTML()) && $node->tagName == 'textarea')
|
| 2941 |
+
$this->markupEvents($html, $oldHtml, $node);
|
| 2942 |
+
}
|
| 2943 |
+
return $this;
|
| 2944 |
+
} else {
|
| 2945 |
+
// FETCH
|
| 2946 |
+
$return = $this->documentWrapper->markup($this->elements, true);
|
| 2947 |
+
$args = func_get_args();
|
| 2948 |
+
foreach(array_slice($args, 1) as $callback) {
|
| 2949 |
+
$return = phpQuery::callbackRun($callback, array($return));
|
| 2950 |
+
}
|
| 2951 |
+
return $return;
|
| 2952 |
+
}
|
| 2953 |
+
}
|
| 2954 |
+
/**
|
| 2955 |
+
* @TODO force xml result
|
| 2956 |
+
*/
|
| 2957 |
+
public function xml($xml = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2958 |
+
$args = func_get_args();
|
| 2959 |
+
return call_user_func_array(array($this, 'html'), $args);
|
| 2960 |
+
}
|
| 2961 |
+
/**
|
| 2962 |
+
* Enter description here...
|
| 2963 |
+
* @TODO force html result
|
| 2964 |
+
*
|
| 2965 |
+
* @return String
|
| 2966 |
+
*/
|
| 2967 |
+
public function htmlOuter($callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2968 |
+
$markup = $this->documentWrapper->markup($this->elements);
|
| 2969 |
+
// pass thou callbacks
|
| 2970 |
+
$args = func_get_args();
|
| 2971 |
+
foreach($args as $callback) {
|
| 2972 |
+
$markup = phpQuery::callbackRun($callback, array($markup));
|
| 2973 |
+
}
|
| 2974 |
+
return $markup;
|
| 2975 |
+
}
|
| 2976 |
+
/**
|
| 2977 |
+
* @TODO force xml result
|
| 2978 |
+
*/
|
| 2979 |
+
public function xmlOuter($callback1 = null, $callback2 = null, $callback3 = null) {
|
| 2980 |
+
$args = func_get_args();
|
| 2981 |
+
return call_user_func_array(array($this, 'htmlOuter'), $args);
|
| 2982 |
+
}
|
| 2983 |
+
public function __toString() {
|
| 2984 |
+
return $this->markupOuter();
|
| 2985 |
+
}
|
| 2986 |
+
/**
|
| 2987 |
+
* Just like html(), but returns markup with VALID (dangerous) PHP tags.
|
| 2988 |
+
*
|
| 2989 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 2990 |
+
* @todo support returning markup with PHP tags when called without param
|
| 2991 |
+
*/
|
| 2992 |
+
public function php($code = null) {
|
| 2993 |
+
return $this->markupPHP($code);
|
| 2994 |
+
}
|
| 2995 |
+
/**
|
| 2996 |
+
* Enter description here...
|
| 2997 |
+
*
|
| 2998 |
+
* @param $code
|
| 2999 |
+
* @return unknown_type
|
| 3000 |
+
*/
|
| 3001 |
+
public function markupPHP($code = null) {
|
| 3002 |
+
return isset($code)
|
| 3003 |
+
? $this->markup(phpQuery::php($code))
|
| 3004 |
+
: phpQuery::markupToPHP($this->markup());
|
| 3005 |
+
}
|
| 3006 |
+
/**
|
| 3007 |
+
* Enter description here...
|
| 3008 |
+
*
|
| 3009 |
+
* @param $code
|
| 3010 |
+
* @return unknown_type
|
| 3011 |
+
*/
|
| 3012 |
+
public function markupOuterPHP() {
|
| 3013 |
+
return phpQuery::markupToPHP($this->markupOuter());
|
| 3014 |
+
}
|
| 3015 |
+
/**
|
| 3016 |
+
* Enter description here...
|
| 3017 |
+
*
|
| 3018 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3019 |
+
*/
|
| 3020 |
+
public function children($selector = null) {
|
| 3021 |
+
$stack = array();
|
| 3022 |
+
foreach($this->stack(1) as $node) {
|
| 3023 |
+
// foreach($node->getElementsByTagName('*') as $newNode) {
|
| 3024 |
+
foreach($node->childNodes as $newNode) {
|
| 3025 |
+
if ($newNode->nodeType != 1)
|
| 3026 |
+
continue;
|
| 3027 |
+
if ($selector && ! $this->is($selector, $newNode))
|
| 3028 |
+
continue;
|
| 3029 |
+
if ($this->elementsContainsNode($newNode, $stack))
|
| 3030 |
+
continue;
|
| 3031 |
+
$stack[] = $newNode;
|
| 3032 |
+
}
|
| 3033 |
+
}
|
| 3034 |
+
$this->elementsBackup = $this->elements;
|
| 3035 |
+
$this->elements = $stack;
|
| 3036 |
+
return $this->newInstance();
|
| 3037 |
+
}
|
| 3038 |
+
/**
|
| 3039 |
+
* Enter description here...
|
| 3040 |
+
*
|
| 3041 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3042 |
+
*/
|
| 3043 |
+
public function ancestors($selector = null) {
|
| 3044 |
+
return $this->children( $selector );
|
| 3045 |
+
}
|
| 3046 |
+
/**
|
| 3047 |
+
* Enter description here...
|
| 3048 |
+
*
|
| 3049 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3050 |
+
*/
|
| 3051 |
+
public function append( $content) {
|
| 3052 |
+
return $this->insert($content, __FUNCTION__);
|
| 3053 |
+
}
|
| 3054 |
+
/**
|
| 3055 |
+
* Enter description here...
|
| 3056 |
+
*
|
| 3057 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3058 |
+
*/
|
| 3059 |
+
public function appendPHP( $content) {
|
| 3060 |
+
return $this->insert("<php><!-- {$content} --></php>", 'append');
|
| 3061 |
+
}
|
| 3062 |
+
/**
|
| 3063 |
+
* Enter description here...
|
| 3064 |
+
*
|
| 3065 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3066 |
+
*/
|
| 3067 |
+
public function appendTo( $seletor) {
|
| 3068 |
+
return $this->insert($seletor, __FUNCTION__);
|
| 3069 |
+
}
|
| 3070 |
+
/**
|
| 3071 |
+
* Enter description here...
|
| 3072 |
+
*
|
| 3073 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3074 |
+
*/
|
| 3075 |
+
public function prepend( $content) {
|
| 3076 |
+
return $this->insert($content, __FUNCTION__);
|
| 3077 |
+
}
|
| 3078 |
+
/**
|
| 3079 |
+
* Enter description here...
|
| 3080 |
+
*
|
| 3081 |
+
* @todo accept many arguments, which are joined, arrays maybe also
|
| 3082 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3083 |
+
*/
|
| 3084 |
+
public function prependPHP( $content) {
|
| 3085 |
+
return $this->insert("<php><!-- {$content} --></php>", 'prepend');
|
| 3086 |
+
}
|
| 3087 |
+
/**
|
| 3088 |
+
* Enter description here...
|
| 3089 |
+
*
|
| 3090 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3091 |
+
*/
|
| 3092 |
+
public function prependTo( $seletor) {
|
| 3093 |
+
return $this->insert($seletor, __FUNCTION__);
|
| 3094 |
+
}
|
| 3095 |
+
/**
|
| 3096 |
+
* Enter description here...
|
| 3097 |
+
*
|
| 3098 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3099 |
+
*/
|
| 3100 |
+
public function before($content) {
|
| 3101 |
+
return $this->insert($content, __FUNCTION__);
|
| 3102 |
+
}
|
| 3103 |
+
/**
|
| 3104 |
+
* Enter description here...
|
| 3105 |
+
*
|
| 3106 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3107 |
+
*/
|
| 3108 |
+
public function beforePHP( $content) {
|
| 3109 |
+
return $this->insert("<php><!-- {$content} --></php>", 'before');
|
| 3110 |
+
}
|
| 3111 |
+
/**
|
| 3112 |
+
* Enter description here...
|
| 3113 |
+
*
|
| 3114 |
+
* @param String|phpQuery
|
| 3115 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3116 |
+
*/
|
| 3117 |
+
public function insertBefore( $seletor) {
|
| 3118 |
+
return $this->insert($seletor, __FUNCTION__);
|
| 3119 |
+
}
|
| 3120 |
+
/**
|
| 3121 |
+
* Enter description here...
|
| 3122 |
+
*
|
| 3123 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3124 |
+
*/
|
| 3125 |
+
public function after( $content) {
|
| 3126 |
+
return $this->insert($content, __FUNCTION__);
|
| 3127 |
+
}
|
| 3128 |
+
/**
|
| 3129 |
+
* Enter description here...
|
| 3130 |
+
*
|
| 3131 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3132 |
+
*/
|
| 3133 |
+
public function afterPHP( $content) {
|
| 3134 |
+
return $this->insert("<php><!-- {$content} --></php>", 'after');
|
| 3135 |
+
}
|
| 3136 |
+
/**
|
| 3137 |
+
* Enter description here...
|
| 3138 |
+
*
|
| 3139 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3140 |
+
*/
|
| 3141 |
+
public function insertAfter( $seletor) {
|
| 3142 |
+
return $this->insert($seletor, __FUNCTION__);
|
| 3143 |
+
}
|
| 3144 |
+
/**
|
| 3145 |
+
* Internal insert method. Don't use it.
|
| 3146 |
+
*
|
| 3147 |
+
* @param unknown_type $target
|
| 3148 |
+
* @param unknown_type $type
|
| 3149 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3150 |
+
* @access private
|
| 3151 |
+
*/
|
| 3152 |
+
public function insert($target, $type) {
|
| 3153 |
+
$this->debug("Inserting data with '{$type}'");
|
| 3154 |
+
$to = false;
|
| 3155 |
+
switch( $type) {
|
| 3156 |
+
case 'appendTo':
|
| 3157 |
+
case 'prependTo':
|
| 3158 |
+
case 'insertBefore':
|
| 3159 |
+
case 'insertAfter':
|
| 3160 |
+
$to = true;
|
| 3161 |
+
}
|
| 3162 |
+
switch(gettype($target)) {
|
| 3163 |
+
case 'string':
|
| 3164 |
+
$insertFrom = $insertTo = array();
|
| 3165 |
+
if ($to) {
|
| 3166 |
+
// INSERT TO
|
| 3167 |
+
$insertFrom = $this->elements;
|
| 3168 |
+
if (phpQuery::isMarkup($target)) {
|
| 3169 |
+
// $target is new markup, import it
|
| 3170 |
+
$insertTo = $this->documentWrapper->import($target);
|
| 3171 |
+
// insert into selected element
|
| 3172 |
+
} else {
|
| 3173 |
+
// $tagret is a selector
|
| 3174 |
+
$thisStack = $this->elements;
|
| 3175 |
+
$this->toRoot();
|
| 3176 |
+
$insertTo = $this->find($target)->elements;
|
| 3177 |
+
$this->elements = $thisStack;
|
| 3178 |
+
}
|
| 3179 |
+
} else {
|
| 3180 |
+
// INSERT FROM
|
| 3181 |
+
$insertTo = $this->elements;
|
| 3182 |
+
$insertFrom = $this->documentWrapper->import($target);
|
| 3183 |
+
}
|
| 3184 |
+
break;
|
| 3185 |
+
case 'object':
|
| 3186 |
+
$insertFrom = $insertTo = array();
|
| 3187 |
+
// phpQuery
|
| 3188 |
+
if ($target instanceof self) {
|
| 3189 |
+
if ($to) {
|
| 3190 |
+
$insertTo = $target->elements;
|
| 3191 |
+
if ($this->documentFragment && $this->stackIsRoot())
|
| 3192 |
+
// get all body children
|
| 3193 |
+
// $loop = $this->find('body > *')->elements;
|
| 3194 |
+
// TODO test it, test it hard...
|
| 3195 |
+
// $loop = $this->newInstance($this->root)->find('> *')->elements;
|
| 3196 |
+
$loop = $this->root->childNodes;
|
| 3197 |
+
else
|
| 3198 |
+
$loop = $this->elements;
|
| 3199 |
+
// import nodes if needed
|
| 3200 |
+
$insertFrom = $this->getDocumentID() == $target->getDocumentID()
|
| 3201 |
+
? $loop
|
| 3202 |
+
: $target->documentWrapper->import($loop);
|
| 3203 |
+
} else {
|
| 3204 |
+
$insertTo = $this->elements;
|
| 3205 |
+
if ( $target->documentFragment && $target->stackIsRoot() )
|
| 3206 |
+
// get all body children
|
| 3207 |
+
// $loop = $target->find('body > *')->elements;
|
| 3208 |
+
$loop = $target->root->childNodes;
|
| 3209 |
+
else
|
| 3210 |
+
$loop = $target->elements;
|
| 3211 |
+
// import nodes if needed
|
| 3212 |
+
$insertFrom = $this->getDocumentID() == $target->getDocumentID()
|
| 3213 |
+
? $loop
|
| 3214 |
+
: $this->documentWrapper->import($loop);
|
| 3215 |
+
}
|
| 3216 |
+
// DOMNODE
|
| 3217 |
+
} elseif ($target instanceof DOMNODE) {
|
| 3218 |
+
// import node if needed
|
| 3219 |
+
// if ( $target->ownerDocument != $this->DOM )
|
| 3220 |
+
// $target = $this->DOM->importNode($target, true);
|
| 3221 |
+
if ( $to) {
|
| 3222 |
+
$insertTo = array($target);
|
| 3223 |
+
if ($this->documentFragment && $this->stackIsRoot())
|
| 3224 |
+
// get all body children
|
| 3225 |
+
$loop = $this->root->childNodes;
|
| 3226 |
+
// $loop = $this->find('body > *')->elements;
|
| 3227 |
+
else
|
| 3228 |
+
$loop = $this->elements;
|
| 3229 |
+
foreach($loop as $fromNode)
|
| 3230 |
+
// import nodes if needed
|
| 3231 |
+
$insertFrom[] = ! $fromNode->ownerDocument->isSameNode($target->ownerDocument)
|
| 3232 |
+
? $target->ownerDocument->importNode($fromNode, true)
|
| 3233 |
+
: $fromNode;
|
| 3234 |
+
} else {
|
| 3235 |
+
// import node if needed
|
| 3236 |
+
if (! $target->ownerDocument->isSameNode($this->document))
|
| 3237 |
+
$target = $this->document->importNode($target, true);
|
| 3238 |
+
$insertTo = $this->elements;
|
| 3239 |
+
$insertFrom[] = $target;
|
| 3240 |
+
}
|
| 3241 |
+
}
|
| 3242 |
+
break;
|
| 3243 |
+
}
|
| 3244 |
+
phpQuery::debug("From ".count($insertFrom)."; To ".count($insertTo)." nodes");
|
| 3245 |
+
foreach($insertTo as $insertNumber => $toNode) {
|
| 3246 |
+
// we need static relative elements in some cases
|
| 3247 |
+
switch( $type) {
|
| 3248 |
+
case 'prependTo':
|
| 3249 |
+
case 'prepend':
|
| 3250 |
+
$firstChild = $toNode->firstChild;
|
| 3251 |
+
break;
|
| 3252 |
+
case 'insertAfter':
|
| 3253 |
+
case 'after':
|
| 3254 |
+
$nextSibling = $toNode->nextSibling;
|
| 3255 |
+
break;
|
| 3256 |
+
}
|
| 3257 |
+
foreach($insertFrom as $fromNode) {
|
| 3258 |
+
// clone if inserted already before
|
| 3259 |
+
$insert = $insertNumber
|
| 3260 |
+
? $fromNode->cloneNode(true)
|
| 3261 |
+
: $fromNode;
|
| 3262 |
+
switch($type) {
|
| 3263 |
+
case 'appendTo':
|
| 3264 |
+
case 'append':
|
| 3265 |
+
// $toNode->insertBefore(
|
| 3266 |
+
// $fromNode,
|
| 3267 |
+
// $toNode->lastChild->nextSibling
|
| 3268 |
+
// );
|
| 3269 |
+
$toNode->appendChild($insert);
|
| 3270 |
+
$eventTarget = $insert;
|
| 3271 |
+
break;
|
| 3272 |
+
case 'prependTo':
|
| 3273 |
+
case 'prepend':
|
| 3274 |
+
$toNode->insertBefore(
|
| 3275 |
+
$insert,
|
| 3276 |
+
$firstChild
|
| 3277 |
+
);
|
| 3278 |
+
break;
|
| 3279 |
+
case 'insertBefore':
|
| 3280 |
+
case 'before':
|
| 3281 |
+
if (! $toNode->parentNode)
|
| 3282 |
+
throw new Exception("No parentNode, can't do {$type}()");
|
| 3283 |
+
else
|
| 3284 |
+
$toNode->parentNode->insertBefore(
|
| 3285 |
+
$insert,
|
| 3286 |
+
$toNode
|
| 3287 |
+
);
|
| 3288 |
+
break;
|
| 3289 |
+
case 'insertAfter':
|
| 3290 |
+
case 'after':
|
| 3291 |
+
if (! $toNode->parentNode)
|
| 3292 |
+
throw new Exception("No parentNode, can't do {$type}()");
|
| 3293 |
+
else
|
| 3294 |
+
$toNode->parentNode->insertBefore(
|
| 3295 |
+
$insert,
|
| 3296 |
+
$nextSibling
|
| 3297 |
+
);
|
| 3298 |
+
break;
|
| 3299 |
+
}
|
| 3300 |
+
// Mutation event
|
| 3301 |
+
$event = new DOMEvent(array(
|
| 3302 |
+
'target' => $insert,
|
| 3303 |
+
'type' => 'DOMNodeInserted'
|
| 3304 |
+
));
|
| 3305 |
+
phpQueryEvents::trigger($this->getDocumentID(),
|
| 3306 |
+
$event->type, array($event), $insert
|
| 3307 |
+
);
|
| 3308 |
+
}
|
| 3309 |
+
}
|
| 3310 |
+
return $this;
|
| 3311 |
+
}
|
| 3312 |
+
/**
|
| 3313 |
+
* Enter description here...
|
| 3314 |
+
*
|
| 3315 |
+
* @return Int
|
| 3316 |
+
*/
|
| 3317 |
+
public function index($subject) {
|
| 3318 |
+
$index = -1;
|
| 3319 |
+
$subject = $subject instanceof phpQueryObject
|
| 3320 |
+
? $subject->elements[0]
|
| 3321 |
+
: $subject;
|
| 3322 |
+
foreach($this->newInstance() as $k => $node) {
|
| 3323 |
+
if ($node->isSameNode($subject))
|
| 3324 |
+
$index = $k;
|
| 3325 |
+
}
|
| 3326 |
+
return $index;
|
| 3327 |
+
}
|
| 3328 |
+
/**
|
| 3329 |
+
* Enter description here...
|
| 3330 |
+
*
|
| 3331 |
+
* @param unknown_type $start
|
| 3332 |
+
* @param unknown_type $end
|
| 3333 |
+
*
|
| 3334 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3335 |
+
* @testme
|
| 3336 |
+
*/
|
| 3337 |
+
public function slice($start, $end = null) {
|
| 3338 |
+
// $last = count($this->elements)-1;
|
| 3339 |
+
// $end = $end
|
| 3340 |
+
// ? min($end, $last)
|
| 3341 |
+
// : $last;
|
| 3342 |
+
// if ($start < 0)
|
| 3343 |
+
// $start = $last+$start;
|
| 3344 |
+
// if ($start > $last)
|
| 3345 |
+
// return array();
|
| 3346 |
+
if ($end > 0)
|
| 3347 |
+
$end = $end-$start;
|
| 3348 |
+
return $this->newInstance(
|
| 3349 |
+
array_slice($this->elements, $start, $end)
|
| 3350 |
+
);
|
| 3351 |
+
}
|
| 3352 |
+
/**
|
| 3353 |
+
* Enter description here...
|
| 3354 |
+
*
|
| 3355 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3356 |
+
*/
|
| 3357 |
+
public function reverse() {
|
| 3358 |
+
$this->elementsBackup = $this->elements;
|
| 3359 |
+
$this->elements = array_reverse($this->elements);
|
| 3360 |
+
return $this->newInstance();
|
| 3361 |
+
}
|
| 3362 |
+
/**
|
| 3363 |
+
* Return joined text content.
|
| 3364 |
+
* @return String
|
| 3365 |
+
*/
|
| 3366 |
+
public function text($text = null, $callback1 = null, $callback2 = null, $callback3 = null) {
|
| 3367 |
+
if (isset($text))
|
| 3368 |
+
return $this->html(htmlspecialchars($text));
|
| 3369 |
+
$args = func_get_args();
|
| 3370 |
+
$args = array_slice($args, 1);
|
| 3371 |
+
$return = '';
|
| 3372 |
+
foreach($this->elements as $node) {
|
| 3373 |
+
$text = $node->textContent;
|
| 3374 |
+
if (count($this->elements) > 1 && $text)
|
| 3375 |
+
$text .= "\n";
|
| 3376 |
+
foreach($args as $callback) {
|
| 3377 |
+
$text = phpQuery::callbackRun($callback, array($text));
|
| 3378 |
+
}
|
| 3379 |
+
$return .= $text;
|
| 3380 |
+
}
|
| 3381 |
+
return $return;
|
| 3382 |
+
}
|
| 3383 |
+
/**
|
| 3384 |
+
* Enter description here...
|
| 3385 |
+
*
|
| 3386 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3387 |
+
*/
|
| 3388 |
+
public function plugin($class, $file = null) {
|
| 3389 |
+
phpQuery::plugin($class, $file);
|
| 3390 |
+
return $this;
|
| 3391 |
+
}
|
| 3392 |
+
/**
|
| 3393 |
+
* Deprecated, use $pq->plugin() instead.
|
| 3394 |
+
*
|
| 3395 |
+
* @deprecated
|
| 3396 |
+
* @param $class
|
| 3397 |
+
* @param $file
|
| 3398 |
+
* @return unknown_type
|
| 3399 |
+
*/
|
| 3400 |
+
public static function extend($class, $file = null) {
|
| 3401 |
+
return $this->plugin($class, $file);
|
| 3402 |
+
}
|
| 3403 |
+
/**
|
| 3404 |
+
*
|
| 3405 |
+
* @access private
|
| 3406 |
+
* @param $method
|
| 3407 |
+
* @param $args
|
| 3408 |
+
* @return unknown_type
|
| 3409 |
+
*/
|
| 3410 |
+
public function __call($method, $args) {
|
| 3411 |
+
$aliasMethods = array('clone', 'empty');
|
| 3412 |
+
if (isset(phpQuery::$extendMethods[$method])) {
|
| 3413 |
+
array_unshift($args, $this);
|
| 3414 |
+
return phpQuery::callbackRun(
|
| 3415 |
+
phpQuery::$extendMethods[$method], $args
|
| 3416 |
+
);
|
| 3417 |
+
} else if (isset(phpQuery::$pluginsMethods[$method])) {
|
| 3418 |
+
array_unshift($args, $this);
|
| 3419 |
+
$class = phpQuery::$pluginsMethods[$method];
|
| 3420 |
+
$realClass = "phpQueryObjectPlugin_$class";
|
| 3421 |
+
$return = call_user_func_array(
|
| 3422 |
+
array($realClass, $method),
|
| 3423 |
+
$args
|
| 3424 |
+
);
|
| 3425 |
+
// XXX deprecate ?
|
| 3426 |
+
return is_null($return)
|
| 3427 |
+
? $this
|
| 3428 |
+
: $return;
|
| 3429 |
+
} else if (in_array($method, $aliasMethods)) {
|
| 3430 |
+
return call_user_func_array(array($this, '_'.$method), $args);
|
| 3431 |
+
} else
|
| 3432 |
+
throw new Exception("Method '{$method}' doesnt exist");
|
| 3433 |
+
}
|
| 3434 |
+
/**
|
| 3435 |
+
* Safe rename of next().
|
| 3436 |
+
*
|
| 3437 |
+
* Use it ONLY when need to call next() on an iterated object (in same time).
|
| 3438 |
+
* Normaly there is no need to do such thing ;)
|
| 3439 |
+
*
|
| 3440 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3441 |
+
* @access private
|
| 3442 |
+
*/
|
| 3443 |
+
public function _next($selector = null) {
|
| 3444 |
+
return $this->newInstance(
|
| 3445 |
+
$this->getElementSiblings('nextSibling', $selector, true)
|
| 3446 |
+
);
|
| 3447 |
+
}
|
| 3448 |
+
/**
|
| 3449 |
+
* Use prev() and next().
|
| 3450 |
+
*
|
| 3451 |
+
* @deprecated
|
| 3452 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3453 |
+
* @access private
|
| 3454 |
+
*/
|
| 3455 |
+
public function _prev($selector = null) {
|
| 3456 |
+
return $this->prev($selector);
|
| 3457 |
+
}
|
| 3458 |
+
/**
|
| 3459 |
+
* Enter description here...
|
| 3460 |
+
*
|
| 3461 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3462 |
+
*/
|
| 3463 |
+
public function prev($selector = null) {
|
| 3464 |
+
return $this->newInstance(
|
| 3465 |
+
$this->getElementSiblings('previousSibling', $selector, true)
|
| 3466 |
+
);
|
| 3467 |
+
}
|
| 3468 |
+
/**
|
| 3469 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3470 |
+
* @todo
|
| 3471 |
+
*/
|
| 3472 |
+
public function prevAll($selector = null) {
|
| 3473 |
+
return $this->newInstance(
|
| 3474 |
+
$this->getElementSiblings('previousSibling', $selector)
|
| 3475 |
+
);
|
| 3476 |
+
}
|
| 3477 |
+
/**
|
| 3478 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3479 |
+
* @todo FIXME: returns source elements insted of next siblings
|
| 3480 |
+
*/
|
| 3481 |
+
public function nextAll($selector = null) {
|
| 3482 |
+
return $this->newInstance(
|
| 3483 |
+
$this->getElementSiblings('nextSibling', $selector)
|
| 3484 |
+
);
|
| 3485 |
+
}
|
| 3486 |
+
/**
|
| 3487 |
+
* @access private
|
| 3488 |
+
*/
|
| 3489 |
+
protected function getElementSiblings($direction, $selector = null, $limitToOne = false) {
|
| 3490 |
+
$stack = array();
|
| 3491 |
+
$count = 0;
|
| 3492 |
+
foreach($this->stack() as $node) {
|
| 3493 |
+
$test = $node;
|
| 3494 |
+
while( isset($test->{$direction}) && $test->{$direction}) {
|
| 3495 |
+
$test = $test->{$direction};
|
| 3496 |
+
if (! $test instanceof DOMELEMENT)
|
| 3497 |
+
continue;
|
| 3498 |
+
$stack[] = $test;
|
| 3499 |
+
if ($limitToOne)
|
| 3500 |
+
break;
|
| 3501 |
+
}
|
| 3502 |
+
}
|
| 3503 |
+
if ($selector) {
|
| 3504 |
+
$stackOld = $this->elements;
|
| 3505 |
+
$this->elements = $stack;
|
| 3506 |
+
$stack = $this->filter($selector, true)->stack();
|
| 3507 |
+
$this->elements = $stackOld;
|
| 3508 |
+
}
|
| 3509 |
+
return $stack;
|
| 3510 |
+
}
|
| 3511 |
+
/**
|
| 3512 |
+
* Enter description here...
|
| 3513 |
+
*
|
| 3514 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3515 |
+
*/
|
| 3516 |
+
public function siblings($selector = null) {
|
| 3517 |
+
$stack = array();
|
| 3518 |
+
$siblings = array_merge(
|
| 3519 |
+
$this->getElementSiblings('previousSibling', $selector),
|
| 3520 |
+
$this->getElementSiblings('nextSibling', $selector)
|
| 3521 |
+
);
|
| 3522 |
+
foreach($siblings as $node) {
|
| 3523 |
+
if (! $this->elementsContainsNode($node, $stack))
|
| 3524 |
+
$stack[] = $node;
|
| 3525 |
+
}
|
| 3526 |
+
return $this->newInstance($stack);
|
| 3527 |
+
}
|
| 3528 |
+
/**
|
| 3529 |
+
* Enter description here...
|
| 3530 |
+
*
|
| 3531 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3532 |
+
*/
|
| 3533 |
+
public function not($selector = null) {
|
| 3534 |
+
if (is_string($selector))
|
| 3535 |
+
phpQuery::debug(array('not', $selector));
|
| 3536 |
+
else
|
| 3537 |
+
phpQuery::debug('not');
|
| 3538 |
+
$stack = array();
|
| 3539 |
+
if ($selector instanceof self || $selector instanceof DOMNODE) {
|
| 3540 |
+
foreach($this->stack() as $node) {
|
| 3541 |
+
if ($selector instanceof self) {
|
| 3542 |
+
$matchFound = false;
|
| 3543 |
+
foreach($selector->stack() as $notNode) {
|
| 3544 |
+
if ($notNode->isSameNode($node))
|
| 3545 |
+
$matchFound = true;
|
| 3546 |
+
}
|
| 3547 |
+
if (! $matchFound)
|
| 3548 |
+
$stack[] = $node;
|
| 3549 |
+
} else if ($selector instanceof DOMNODE) {
|
| 3550 |
+
if (! $selector->isSameNode($node))
|
| 3551 |
+
$stack[] = $node;
|
| 3552 |
+
} else {
|
| 3553 |
+
if (! $this->is($selector))
|
| 3554 |
+
$stack[] = $node;
|
| 3555 |
+
}
|
| 3556 |
+
}
|
| 3557 |
+
} else {
|
| 3558 |
+
$orgStack = $this->stack();
|
| 3559 |
+
$matched = $this->filter($selector, true)->stack();
|
| 3560 |
+
// $matched = array();
|
| 3561 |
+
// // simulate OR in filter() instead of AND 5y
|
| 3562 |
+
// foreach($this->parseSelector($selector) as $s) {
|
| 3563 |
+
// $matched = array_merge($matched,
|
| 3564 |
+
// $this->filter(array($s))->stack()
|
| 3565 |
+
// );
|
| 3566 |
+
// }
|
| 3567 |
+
foreach($orgStack as $node)
|
| 3568 |
+
if (! $this->elementsContainsNode($node, $matched))
|
| 3569 |
+
$stack[] = $node;
|
| 3570 |
+
}
|
| 3571 |
+
return $this->newInstance($stack);
|
| 3572 |
+
}
|
| 3573 |
+
/**
|
| 3574 |
+
* Enter description here...
|
| 3575 |
+
*
|
| 3576 |
+
* @param string|phpQueryObject
|
| 3577 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3578 |
+
*/
|
| 3579 |
+
public function add($selector = null) {
|
| 3580 |
+
if (! $selector)
|
| 3581 |
+
return $this;
|
| 3582 |
+
$stack = array();
|
| 3583 |
+
$this->elementsBackup = $this->elements;
|
| 3584 |
+
$found = phpQuery::pq($selector, $this->getDocumentID());
|
| 3585 |
+
$this->merge($found->elements);
|
| 3586 |
+
return $this->newInstance();
|
| 3587 |
+
}
|
| 3588 |
+
/**
|
| 3589 |
+
* @access private
|
| 3590 |
+
*/
|
| 3591 |
+
protected function merge() {
|
| 3592 |
+
foreach(func_get_args() as $nodes)
|
| 3593 |
+
foreach($nodes as $newNode )
|
| 3594 |
+
if (! $this->elementsContainsNode($newNode) )
|
| 3595 |
+
$this->elements[] = $newNode;
|
| 3596 |
+
}
|
| 3597 |
+
/**
|
| 3598 |
+
* @access private
|
| 3599 |
+
* TODO refactor to stackContainsNode
|
| 3600 |
+
*/
|
| 3601 |
+
protected function elementsContainsNode($nodeToCheck, $elementsStack = null) {
|
| 3602 |
+
$loop = ! is_null($elementsStack)
|
| 3603 |
+
? $elementsStack
|
| 3604 |
+
: $this->elements;
|
| 3605 |
+
foreach($loop as $node) {
|
| 3606 |
+
if ( $node->isSameNode( $nodeToCheck ) )
|
| 3607 |
+
return true;
|
| 3608 |
+
}
|
| 3609 |
+
return false;
|
| 3610 |
+
}
|
| 3611 |
+
/**
|
| 3612 |
+
* Enter description here...
|
| 3613 |
+
*
|
| 3614 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3615 |
+
*/
|
| 3616 |
+
public function parent($selector = null) {
|
| 3617 |
+
$stack = array();
|
| 3618 |
+
foreach($this->elements as $node )
|
| 3619 |
+
if ( $node->parentNode && ! $this->elementsContainsNode($node->parentNode, $stack) )
|
| 3620 |
+
$stack[] = $node->parentNode;
|
| 3621 |
+
$this->elementsBackup = $this->elements;
|
| 3622 |
+
$this->elements = $stack;
|
| 3623 |
+
if ( $selector )
|
| 3624 |
+
$this->filter($selector, true);
|
| 3625 |
+
return $this->newInstance();
|
| 3626 |
+
}
|
| 3627 |
+
/**
|
| 3628 |
+
* Enter description here...
|
| 3629 |
+
*
|
| 3630 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3631 |
+
*/
|
| 3632 |
+
public function parents($selector = null) {
|
| 3633 |
+
$stack = array();
|
| 3634 |
+
if (! $this->elements )
|
| 3635 |
+
$this->debug('parents() - stack empty');
|
| 3636 |
+
foreach($this->elements as $node) {
|
| 3637 |
+
$test = $node;
|
| 3638 |
+
while( $test->parentNode) {
|
| 3639 |
+
$test = $test->parentNode;
|
| 3640 |
+
if ($this->isRoot($test))
|
| 3641 |
+
break;
|
| 3642 |
+
if (! $this->elementsContainsNode($test, $stack)) {
|
| 3643 |
+
$stack[] = $test;
|
| 3644 |
+
continue;
|
| 3645 |
+
}
|
| 3646 |
+
}
|
| 3647 |
+
}
|
| 3648 |
+
$this->elementsBackup = $this->elements;
|
| 3649 |
+
$this->elements = $stack;
|
| 3650 |
+
if ( $selector )
|
| 3651 |
+
$this->filter($selector, true);
|
| 3652 |
+
return $this->newInstance();
|
| 3653 |
+
}
|
| 3654 |
+
/**
|
| 3655 |
+
* Internal stack iterator.
|
| 3656 |
+
*
|
| 3657 |
+
* @access private
|
| 3658 |
+
*/
|
| 3659 |
+
public function stack($nodeTypes = null) {
|
| 3660 |
+
if (!isset($nodeTypes))
|
| 3661 |
+
return $this->elements;
|
| 3662 |
+
if (!is_array($nodeTypes))
|
| 3663 |
+
$nodeTypes = array($nodeTypes);
|
| 3664 |
+
$return = array();
|
| 3665 |
+
foreach($this->elements as $node) {
|
| 3666 |
+
if (in_array($node->nodeType, $nodeTypes))
|
| 3667 |
+
$return[] = $node;
|
| 3668 |
+
}
|
| 3669 |
+
return $return;
|
| 3670 |
+
}
|
| 3671 |
+
// TODO phpdoc; $oldAttr is result of hasAttribute, before any changes
|
| 3672 |
+
protected function attrEvents($attr, $oldAttr, $oldValue, $node) {
|
| 3673 |
+
// skip events for XML documents
|
| 3674 |
+
if (! $this->isXHTML() && ! $this->isHTML())
|
| 3675 |
+
return;
|
| 3676 |
+
$event = null;
|
| 3677 |
+
// identify
|
| 3678 |
+
$isInputValue = $node->tagName == 'input'
|
| 3679 |
+
&& (
|
| 3680 |
+
in_array($node->getAttribute('type'),
|
| 3681 |
+
array('text', 'password', 'hidden'))
|
| 3682 |
+
|| !$node->getAttribute('type')
|
| 3683 |
+
);
|
| 3684 |
+
$isRadio = $node->tagName == 'input'
|
| 3685 |
+
&& $node->getAttribute('type') == 'radio';
|
| 3686 |
+
$isCheckbox = $node->tagName == 'input'
|
| 3687 |
+
&& $node->getAttribute('type') == 'checkbox';
|
| 3688 |
+
$isOption = $node->tagName == 'option';
|
| 3689 |
+
if ($isInputValue && $attr == 'value' && $oldValue != $node->getAttribute($attr)) {
|
| 3690 |
+
$event = new DOMEvent(array(
|
| 3691 |
+
'target' => $node,
|
| 3692 |
+
'type' => 'change'
|
| 3693 |
+
));
|
| 3694 |
+
} else if (($isRadio || $isCheckbox) && $attr == 'checked' && (
|
| 3695 |
+
// check
|
| 3696 |
+
(! $oldAttr && $node->hasAttribute($attr))
|
| 3697 |
+
// un-check
|
| 3698 |
+
|| (! $node->hasAttribute($attr) && $oldAttr)
|
| 3699 |
+
)) {
|
| 3700 |
+
$event = new DOMEvent(array(
|
| 3701 |
+
'target' => $node,
|
| 3702 |
+
'type' => 'change'
|
| 3703 |
+
));
|
| 3704 |
+
} else if ($isOption && $node->parentNode && $attr == 'selected' && (
|
| 3705 |
+
// select
|
| 3706 |
+
(! $oldAttr && $node->hasAttribute($attr))
|
| 3707 |
+
// un-select
|
| 3708 |
+
|| (! $node->hasAttribute($attr) && $oldAttr)
|
| 3709 |
+
)) {
|
| 3710 |
+
$event = new DOMEvent(array(
|
| 3711 |
+
'target' => $node->parentNode,
|
| 3712 |
+
'type' => 'change'
|
| 3713 |
+
));
|
| 3714 |
+
}
|
| 3715 |
+
if ($event) {
|
| 3716 |
+
phpQueryEvents::trigger($this->getDocumentID(),
|
| 3717 |
+
$event->type, array($event), $node
|
| 3718 |
+
);
|
| 3719 |
+
}
|
| 3720 |
+
}
|
| 3721 |
+
public function attr($attr = null, $value = null) {
|
| 3722 |
+
foreach($this->stack(1) as $node) {
|
| 3723 |
+
if (! is_null($value)) {
|
| 3724 |
+
$loop = $attr == '*'
|
| 3725 |
+
? $this->getNodeAttrs($node)
|
| 3726 |
+
: array($attr);
|
| 3727 |
+
foreach($loop as $a) {
|
| 3728 |
+
$oldValue = $node->getAttribute($a);
|
| 3729 |
+
$oldAttr = $node->hasAttribute($a);
|
| 3730 |
+
// TODO raises an error when charset other than UTF-8
|
| 3731 |
+
// while document's charset is also not UTF-8
|
| 3732 |
+
@$node->setAttribute($a, $value);
|
| 3733 |
+
$this->attrEvents($a, $oldAttr, $oldValue, $node);
|
| 3734 |
+
}
|
| 3735 |
+
} else if ($attr == '*') {
|
| 3736 |
+
// jQuery difference
|
| 3737 |
+
$return = array();
|
| 3738 |
+
foreach($node->attributes as $n => $v)
|
| 3739 |
+
$return[$n] = $v->value;
|
| 3740 |
+
return $return;
|
| 3741 |
+
} else
|
| 3742 |
+
return $node->hasAttribute($attr)
|
| 3743 |
+
? $node->getAttribute($attr)
|
| 3744 |
+
: null;
|
| 3745 |
+
}
|
| 3746 |
+
return is_null($value)
|
| 3747 |
+
? '' : $this;
|
| 3748 |
+
}
|
| 3749 |
+
/**
|
| 3750 |
+
* @access private
|
| 3751 |
+
*/
|
| 3752 |
+
protected function getNodeAttrs($node) {
|
| 3753 |
+
$return = array();
|
| 3754 |
+
foreach($node->attributes as $n => $o)
|
| 3755 |
+
$return[] = $n;
|
| 3756 |
+
return $return;
|
| 3757 |
+
}
|
| 3758 |
+
/**
|
| 3759 |
+
* Enter description here...
|
| 3760 |
+
*
|
| 3761 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3762 |
+
* @todo check CDATA ???
|
| 3763 |
+
*/
|
| 3764 |
+
public function attrPHP($attr, $code) {
|
| 3765 |
+
if (! is_null($code)) {
|
| 3766 |
+
$value = '<'.'?php '.$code.' ?'.'>';
|
| 3767 |
+
// TODO tempolary solution
|
| 3768 |
+
// http://code.google.com/p/phpquery/issues/detail?id=17
|
| 3769 |
+
// if (function_exists('mb_detect_encoding') && mb_detect_encoding($value) == 'ASCII')
|
| 3770 |
+
// $value = mb_convert_encoding($value, 'UTF-8', 'HTML-ENTITIES');
|
| 3771 |
+
}
|
| 3772 |
+
foreach($this->stack(1) as $node) {
|
| 3773 |
+
if (! is_null($code)) {
|
| 3774 |
+
// $attrNode = $this->DOM->createAttribute($attr);
|
| 3775 |
+
$node->setAttribute($attr, $value);
|
| 3776 |
+
// $attrNode->value = $value;
|
| 3777 |
+
// $node->appendChild($attrNode);
|
| 3778 |
+
} else if ( $attr == '*') {
|
| 3779 |
+
// jQuery diff
|
| 3780 |
+
$return = array();
|
| 3781 |
+
foreach($node->attributes as $n => $v)
|
| 3782 |
+
$return[$n] = $v->value;
|
| 3783 |
+
return $return;
|
| 3784 |
+
} else
|
| 3785 |
+
return $node->getAttribute($attr);
|
| 3786 |
+
}
|
| 3787 |
+
return $this;
|
| 3788 |
+
}
|
| 3789 |
+
/**
|
| 3790 |
+
* Enter description here...
|
| 3791 |
+
*
|
| 3792 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3793 |
+
*/
|
| 3794 |
+
public function removeAttr($attr) {
|
| 3795 |
+
foreach($this->stack(1) as $node) {
|
| 3796 |
+
$loop = $attr == '*'
|
| 3797 |
+
? $this->getNodeAttrs($node)
|
| 3798 |
+
: array($attr);
|
| 3799 |
+
foreach($loop as $a) {
|
| 3800 |
+
$oldValue = $node->getAttribute($a);
|
| 3801 |
+
$node->removeAttribute($a);
|
| 3802 |
+
$this->attrEvents($a, $oldValue, null, $node);
|
| 3803 |
+
}
|
| 3804 |
+
}
|
| 3805 |
+
return $this;
|
| 3806 |
+
}
|
| 3807 |
+
/**
|
| 3808 |
+
* Return form element value.
|
| 3809 |
+
*
|
| 3810 |
+
* @return String Fields value.
|
| 3811 |
+
*/
|
| 3812 |
+
public function val($val = null) {
|
| 3813 |
+
if (! isset($val)) {
|
| 3814 |
+
if ($this->eq(0)->is('select')) {
|
| 3815 |
+
$selected = $this->eq(0)->find('option[selected=selected]');
|
| 3816 |
+
if ($selected->is('[value]'))
|
| 3817 |
+
return $selected->attr('value');
|
| 3818 |
+
else
|
| 3819 |
+
return $selected->text();
|
| 3820 |
+
} else if ($this->eq(0)->is('textarea'))
|
| 3821 |
+
return $this->eq(0)->markup();
|
| 3822 |
+
else
|
| 3823 |
+
return $this->eq(0)->attr('value');
|
| 3824 |
+
} else {
|
| 3825 |
+
$_val = null;
|
| 3826 |
+
foreach($this->stack(1) as $node) {
|
| 3827 |
+
$node = pq($node, $this->getDocumentID());
|
| 3828 |
+
if (is_array($val) && in_array($node->attr('type'), array('checkbox', 'radio'))) {
|
| 3829 |
+
$isChecked = in_array($node->attr('value'), $val)
|
| 3830 |
+
|| in_array($node->attr('name'), $val);
|
| 3831 |
+
if ($isChecked)
|
| 3832 |
+
$node->attr('checked', 'checked');
|
| 3833 |
+
else
|
| 3834 |
+
$node->removeAttr('checked');
|
| 3835 |
+
} else if ($node->get(0)->tagName == 'select') {
|
| 3836 |
+
if (! isset($_val)) {
|
| 3837 |
+
$_val = array();
|
| 3838 |
+
if (! is_array($val))
|
| 3839 |
+
$_val = array((string)$val);
|
| 3840 |
+
else
|
| 3841 |
+
foreach($val as $v)
|
| 3842 |
+
$_val[] = $v;
|
| 3843 |
+
}
|
| 3844 |
+
foreach($node['option']->stack(1) as $option) {
|
| 3845 |
+
$option = pq($option, $this->getDocumentID());
|
| 3846 |
+
$selected = false;
|
| 3847 |
+
// XXX: workaround for string comparsion, see issue #96
|
| 3848 |
+
// http://code.google.com/p/phpquery/issues/detail?id=96
|
| 3849 |
+
$selected = is_null($option->attr('value'))
|
| 3850 |
+
? in_array($option->markup(), $_val)
|
| 3851 |
+
: in_array($option->attr('value'), $_val);
|
| 3852 |
+
// $optionValue = $option->attr('value');
|
| 3853 |
+
// $optionText = $option->text();
|
| 3854 |
+
// $optionTextLenght = mb_strlen($optionText);
|
| 3855 |
+
// foreach($_val as $v)
|
| 3856 |
+
// if ($optionValue == $v)
|
| 3857 |
+
// $selected = true;
|
| 3858 |
+
// else if ($optionText == $v && $optionTextLenght == mb_strlen($v))
|
| 3859 |
+
// $selected = true;
|
| 3860 |
+
if ($selected)
|
| 3861 |
+
$option->attr('selected', 'selected');
|
| 3862 |
+
else
|
| 3863 |
+
$option->removeAttr('selected');
|
| 3864 |
+
}
|
| 3865 |
+
} else if ($node->get(0)->tagName == 'textarea')
|
| 3866 |
+
$node->markup($val);
|
| 3867 |
+
else
|
| 3868 |
+
$node->attr('value', $val);
|
| 3869 |
+
}
|
| 3870 |
+
}
|
| 3871 |
+
return $this;
|
| 3872 |
+
}
|
| 3873 |
+
/**
|
| 3874 |
+
* Enter description here...
|
| 3875 |
+
*
|
| 3876 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3877 |
+
*/
|
| 3878 |
+
public function andSelf() {
|
| 3879 |
+
if ( $this->previous )
|
| 3880 |
+
$this->elements = array_merge($this->elements, $this->previous->elements);
|
| 3881 |
+
return $this;
|
| 3882 |
+
}
|
| 3883 |
+
/**
|
| 3884 |
+
* Enter description here...
|
| 3885 |
+
*
|
| 3886 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3887 |
+
*/
|
| 3888 |
+
public function addClass( $className) {
|
| 3889 |
+
if (! $className)
|
| 3890 |
+
return $this;
|
| 3891 |
+
foreach($this->stack(1) as $node) {
|
| 3892 |
+
if (! $this->is(".$className", $node))
|
| 3893 |
+
$node->setAttribute(
|
| 3894 |
+
'class',
|
| 3895 |
+
trim($node->getAttribute('class').' '.$className)
|
| 3896 |
+
);
|
| 3897 |
+
}
|
| 3898 |
+
return $this;
|
| 3899 |
+
}
|
| 3900 |
+
/**
|
| 3901 |
+
* Enter description here...
|
| 3902 |
+
*
|
| 3903 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3904 |
+
*/
|
| 3905 |
+
public function addClassPHP( $className) {
|
| 3906 |
+
foreach($this->stack(1) as $node) {
|
| 3907 |
+
$classes = $node->getAttribute('class');
|
| 3908 |
+
$newValue = $classes
|
| 3909 |
+
? $classes.' <'.'?php '.$className.' ?'.'>'
|
| 3910 |
+
: '<'.'?php '.$className.' ?'.'>';
|
| 3911 |
+
$node->setAttribute('class', $newValue);
|
| 3912 |
+
}
|
| 3913 |
+
return $this;
|
| 3914 |
+
}
|
| 3915 |
+
/**
|
| 3916 |
+
* Enter description here...
|
| 3917 |
+
*
|
| 3918 |
+
* @param string $className
|
| 3919 |
+
* @return bool
|
| 3920 |
+
*/
|
| 3921 |
+
public function hasClass($className) {
|
| 3922 |
+
foreach($this->stack(1) as $node) {
|
| 3923 |
+
if ( $this->is(".$className", $node))
|
| 3924 |
+
return true;
|
| 3925 |
+
}
|
| 3926 |
+
return false;
|
| 3927 |
+
}
|
| 3928 |
+
/**
|
| 3929 |
+
* Enter description here...
|
| 3930 |
+
*
|
| 3931 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3932 |
+
*/
|
| 3933 |
+
public function removeClass($className) {
|
| 3934 |
+
foreach($this->stack(1) as $node) {
|
| 3935 |
+
$classes = explode( ' ', $node->getAttribute('class'));
|
| 3936 |
+
if ( in_array($className, $classes)) {
|
| 3937 |
+
$classes = array_diff($classes, array($className));
|
| 3938 |
+
if ( $classes )
|
| 3939 |
+
$node->setAttribute('class', implode(' ', $classes));
|
| 3940 |
+
else
|
| 3941 |
+
$node->removeAttribute('class');
|
| 3942 |
+
}
|
| 3943 |
+
}
|
| 3944 |
+
return $this;
|
| 3945 |
+
}
|
| 3946 |
+
/**
|
| 3947 |
+
* Enter description here...
|
| 3948 |
+
*
|
| 3949 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3950 |
+
*/
|
| 3951 |
+
public function toggleClass($className) {
|
| 3952 |
+
foreach($this->stack(1) as $node) {
|
| 3953 |
+
if ( $this->is( $node, '.'.$className ))
|
| 3954 |
+
$this->removeClass($className);
|
| 3955 |
+
else
|
| 3956 |
+
$this->addClass($className);
|
| 3957 |
+
}
|
| 3958 |
+
return $this;
|
| 3959 |
+
}
|
| 3960 |
+
/**
|
| 3961 |
+
* Proper name without underscore (just ->empty()) also works.
|
| 3962 |
+
*
|
| 3963 |
+
* Removes all child nodes from the set of matched elements.
|
| 3964 |
+
*
|
| 3965 |
+
* Example:
|
| 3966 |
+
* pq("p")._empty()
|
| 3967 |
+
*
|
| 3968 |
+
* HTML:
|
| 3969 |
+
* <p>Hello, <span>Person</span> <a href="#">and person</a></p>
|
| 3970 |
+
*
|
| 3971 |
+
* Result:
|
| 3972 |
+
* [ <p></p> ]
|
| 3973 |
+
*
|
| 3974 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3975 |
+
* @access private
|
| 3976 |
+
*/
|
| 3977 |
+
public function _empty() {
|
| 3978 |
+
foreach($this->stack(1) as $node) {
|
| 3979 |
+
// thx to 'dave at dgx dot cz'
|
| 3980 |
+
$node->nodeValue = '';
|
| 3981 |
+
}
|
| 3982 |
+
return $this;
|
| 3983 |
+
}
|
| 3984 |
+
/**
|
| 3985 |
+
* Enter description here...
|
| 3986 |
+
*
|
| 3987 |
+
* @param array|string $callback Expects $node as first param, $index as second
|
| 3988 |
+
* @param array $scope External variables passed to callback. Use compact('varName1', 'varName2'...) and extract($scope)
|
| 3989 |
+
* @param array $arg1 Will ba passed as third and futher args to callback.
|
| 3990 |
+
* @param array $arg2 Will ba passed as fourth and futher args to callback, and so on...
|
| 3991 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 3992 |
+
*/
|
| 3993 |
+
public function each($callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 3994 |
+
$paramStructure = null;
|
| 3995 |
+
if (func_num_args() > 1) {
|
| 3996 |
+
$paramStructure = func_get_args();
|
| 3997 |
+
$paramStructure = array_slice($paramStructure, 1);
|
| 3998 |
+
}
|
| 3999 |
+
foreach($this->elements as $v)
|
| 4000 |
+
phpQuery::callbackRun($callback, array($v), $paramStructure);
|
| 4001 |
+
return $this;
|
| 4002 |
+
}
|
| 4003 |
+
/**
|
| 4004 |
+
* Run callback on actual object.
|
| 4005 |
+
*
|
| 4006 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4007 |
+
*/
|
| 4008 |
+
public function callback($callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 4009 |
+
$params = func_get_args();
|
| 4010 |
+
$params[0] = $this;
|
| 4011 |
+
phpQuery::callbackRun($callback, $params);
|
| 4012 |
+
return $this;
|
| 4013 |
+
}
|
| 4014 |
+
/**
|
| 4015 |
+
* Enter description here...
|
| 4016 |
+
*
|
| 4017 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4018 |
+
* @todo add $scope and $args as in each() ???
|
| 4019 |
+
*/
|
| 4020 |
+
public function map($callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 4021 |
+
// $stack = array();
|
| 4022 |
+
//// foreach($this->newInstance() as $node) {
|
| 4023 |
+
// foreach($this->newInstance() as $node) {
|
| 4024 |
+
// $result = call_user_func($callback, $node);
|
| 4025 |
+
// if ($result)
|
| 4026 |
+
// $stack[] = $result;
|
| 4027 |
+
// }
|
| 4028 |
+
$params = func_get_args();
|
| 4029 |
+
array_unshift($params, $this->elements);
|
| 4030 |
+
return $this->newInstance(
|
| 4031 |
+
call_user_func_array(array('phpQuery', 'map'), $params)
|
| 4032 |
+
// phpQuery::map($this->elements, $callback)
|
| 4033 |
+
);
|
| 4034 |
+
}
|
| 4035 |
+
/**
|
| 4036 |
+
* Enter description here...
|
| 4037 |
+
*
|
| 4038 |
+
* @param <type> $key
|
| 4039 |
+
* @param <type> $value
|
| 4040 |
+
*/
|
| 4041 |
+
public function data($key, $value = null) {
|
| 4042 |
+
if (! isset($value)) {
|
| 4043 |
+
// TODO? implement specific jQuery behavior od returning parent values
|
| 4044 |
+
// is child which we look up doesn't exist
|
| 4045 |
+
return phpQuery::data($this->get(0), $key, $value, $this->getDocumentID());
|
| 4046 |
+
} else {
|
| 4047 |
+
foreach($this as $node)
|
| 4048 |
+
phpQuery::data($node, $key, $value, $this->getDocumentID());
|
| 4049 |
+
return $this;
|
| 4050 |
+
}
|
| 4051 |
+
}
|
| 4052 |
+
/**
|
| 4053 |
+
* Enter description here...
|
| 4054 |
+
*
|
| 4055 |
+
* @param <type> $key
|
| 4056 |
+
*/
|
| 4057 |
+
public function removeData($key) {
|
| 4058 |
+
foreach($this as $node)
|
| 4059 |
+
phpQuery::removeData($node, $key, $this->getDocumentID());
|
| 4060 |
+
return $this;
|
| 4061 |
+
}
|
| 4062 |
+
// INTERFACE IMPLEMENTATIONS
|
| 4063 |
+
|
| 4064 |
+
// ITERATOR INTERFACE
|
| 4065 |
+
/**
|
| 4066 |
+
* @access private
|
| 4067 |
+
*/
|
| 4068 |
+
public function rewind(){
|
| 4069 |
+
$this->debug('iterating foreach');
|
| 4070 |
+
// phpQuery::selectDocument($this->getDocumentID());
|
| 4071 |
+
$this->elementsBackup = $this->elements;
|
| 4072 |
+
$this->elementsInterator = $this->elements;
|
| 4073 |
+
$this->valid = isset( $this->elements[0] )
|
| 4074 |
+
? 1 : 0;
|
| 4075 |
+
// $this->elements = $this->valid
|
| 4076 |
+
// ? array($this->elements[0])
|
| 4077 |
+
// : array();
|
| 4078 |
+
$this->current = 0;
|
| 4079 |
+
}
|
| 4080 |
+
/**
|
| 4081 |
+
* @access private
|
| 4082 |
+
*/
|
| 4083 |
+
public function current(){
|
| 4084 |
+
return $this->elementsInterator[ $this->current ];
|
| 4085 |
+
}
|
| 4086 |
+
/**
|
| 4087 |
+
* @access private
|
| 4088 |
+
*/
|
| 4089 |
+
public function key(){
|
| 4090 |
+
return $this->current;
|
| 4091 |
+
}
|
| 4092 |
+
/**
|
| 4093 |
+
* Double-function method.
|
| 4094 |
+
*
|
| 4095 |
+
* First: main iterator interface method.
|
| 4096 |
+
* Second: Returning next sibling, alias for _next().
|
| 4097 |
+
*
|
| 4098 |
+
* Proper functionality is choosed automagicaly.
|
| 4099 |
+
*
|
| 4100 |
+
* @see phpQueryObject::_next()
|
| 4101 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4102 |
+
*/
|
| 4103 |
+
public function next($cssSelector = null){
|
| 4104 |
+
// if ($cssSelector || $this->valid)
|
| 4105 |
+
// return $this->_next($cssSelector);
|
| 4106 |
+
$this->valid = isset( $this->elementsInterator[ $this->current+1 ] )
|
| 4107 |
+
? true
|
| 4108 |
+
: false;
|
| 4109 |
+
if (! $this->valid && $this->elementsInterator) {
|
| 4110 |
+
$this->elementsInterator = null;
|
| 4111 |
+
} else if ($this->valid) {
|
| 4112 |
+
$this->current++;
|
| 4113 |
+
} else {
|
| 4114 |
+
return $this->_next($cssSelector);
|
| 4115 |
+
}
|
| 4116 |
+
}
|
| 4117 |
+
/**
|
| 4118 |
+
* @access private
|
| 4119 |
+
*/
|
| 4120 |
+
public function valid(){
|
| 4121 |
+
return $this->valid;
|
| 4122 |
+
}
|
| 4123 |
+
// ITERATOR INTERFACE END
|
| 4124 |
+
// ARRAYACCESS INTERFACE
|
| 4125 |
+
/**
|
| 4126 |
+
* @access private
|
| 4127 |
+
*/
|
| 4128 |
+
public function offsetExists($offset) {
|
| 4129 |
+
return $this->find($offset)->size() > 0;
|
| 4130 |
+
}
|
| 4131 |
+
/**
|
| 4132 |
+
* @access private
|
| 4133 |
+
*/
|
| 4134 |
+
public function offsetGet($offset) {
|
| 4135 |
+
return $this->find($offset);
|
| 4136 |
+
}
|
| 4137 |
+
/**
|
| 4138 |
+
* @access private
|
| 4139 |
+
*/
|
| 4140 |
+
public function offsetSet($offset, $value) {
|
| 4141 |
+
// $this->find($offset)->replaceWith($value);
|
| 4142 |
+
$this->find($offset)->html($value);
|
| 4143 |
+
}
|
| 4144 |
+
/**
|
| 4145 |
+
* @access private
|
| 4146 |
+
*/
|
| 4147 |
+
public function offsetUnset($offset) {
|
| 4148 |
+
// empty
|
| 4149 |
+
throw new Exception("Can't do unset, use array interface only for calling queries and replacing HTML.");
|
| 4150 |
+
}
|
| 4151 |
+
// ARRAYACCESS INTERFACE END
|
| 4152 |
+
/**
|
| 4153 |
+
* Returns node's XPath.
|
| 4154 |
+
*
|
| 4155 |
+
* @param unknown_type $oneNode
|
| 4156 |
+
* @return string
|
| 4157 |
+
* @TODO use native getNodePath is avaible
|
| 4158 |
+
* @access private
|
| 4159 |
+
*/
|
| 4160 |
+
protected function getNodeXpath($oneNode = null, $namespace = null) {
|
| 4161 |
+
$return = array();
|
| 4162 |
+
$loop = $oneNode
|
| 4163 |
+
? array($oneNode)
|
| 4164 |
+
: $this->elements;
|
| 4165 |
+
// if ($namespace)
|
| 4166 |
+
// $namespace .= ':';
|
| 4167 |
+
foreach($loop as $node) {
|
| 4168 |
+
if ($node instanceof DOMDOCUMENT) {
|
| 4169 |
+
$return[] = '';
|
| 4170 |
+
continue;
|
| 4171 |
+
}
|
| 4172 |
+
$xpath = array();
|
| 4173 |
+
while(! ($node instanceof DOMDOCUMENT)) {
|
| 4174 |
+
$i = 1;
|
| 4175 |
+
$sibling = $node;
|
| 4176 |
+
while($sibling->previousSibling) {
|
| 4177 |
+
$sibling = $sibling->previousSibling;
|
| 4178 |
+
$isElement = $sibling instanceof DOMELEMENT;
|
| 4179 |
+
if ($isElement && $sibling->tagName == $node->tagName)
|
| 4180 |
+
$i++;
|
| 4181 |
+
}
|
| 4182 |
+
$xpath[] = $this->isXML()
|
| 4183 |
+
? "*[local-name()='{$node->tagName}'][{$i}]"
|
| 4184 |
+
: "{$node->tagName}[{$i}]";
|
| 4185 |
+
$node = $node->parentNode;
|
| 4186 |
+
}
|
| 4187 |
+
$xpath = join('/', array_reverse($xpath));
|
| 4188 |
+
$return[] = '/'.$xpath;
|
| 4189 |
+
}
|
| 4190 |
+
return $oneNode
|
| 4191 |
+
? $return[0]
|
| 4192 |
+
: $return;
|
| 4193 |
+
}
|
| 4194 |
+
// HELPERS
|
| 4195 |
+
public function whois($oneNode = null) {
|
| 4196 |
+
$return = array();
|
| 4197 |
+
$loop = $oneNode
|
| 4198 |
+
? array( $oneNode )
|
| 4199 |
+
: $this->elements;
|
| 4200 |
+
foreach($loop as $node) {
|
| 4201 |
+
if (isset($node->tagName)) {
|
| 4202 |
+
$tag = in_array($node->tagName, array('php', 'js'))
|
| 4203 |
+
? strtoupper($node->tagName)
|
| 4204 |
+
: $node->tagName;
|
| 4205 |
+
$return[] = $tag
|
| 4206 |
+
.($node->getAttribute('id')
|
| 4207 |
+
? '#'.$node->getAttribute('id'):'')
|
| 4208 |
+
.($node->getAttribute('class')
|
| 4209 |
+
? '.'.join('.', split(' ', $node->getAttribute('class'))):'')
|
| 4210 |
+
.($node->getAttribute('name')
|
| 4211 |
+
? '[name="'.$node->getAttribute('name').'"]':'')
|
| 4212 |
+
.($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') === false
|
| 4213 |
+
? '[value="'.substr(str_replace("\n", '', $node->getAttribute('value')), 0, 15).'"]':'')
|
| 4214 |
+
.($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') !== false
|
| 4215 |
+
? '[value=PHP]':'')
|
| 4216 |
+
.($node->getAttribute('selected')
|
| 4217 |
+
? '[selected]':'')
|
| 4218 |
+
.($node->getAttribute('checked')
|
| 4219 |
+
? '[checked]':'')
|
| 4220 |
+
;
|
| 4221 |
+
} else if ($node instanceof DOMTEXT) {
|
| 4222 |
+
if (trim($node->textContent))
|
| 4223 |
+
$return[] = 'Text:'.substr(str_replace("\n", ' ', $node->textContent), 0, 15);
|
| 4224 |
+
} else {
|
| 4225 |
+
|
| 4226 |
+
}
|
| 4227 |
+
}
|
| 4228 |
+
return $oneNode && isset($return[0])
|
| 4229 |
+
? $return[0]
|
| 4230 |
+
: $return;
|
| 4231 |
+
}
|
| 4232 |
+
/**
|
| 4233 |
+
* Dump htmlOuter and preserve chain. Usefull for debugging.
|
| 4234 |
+
*
|
| 4235 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4236 |
+
*
|
| 4237 |
+
*/
|
| 4238 |
+
public function dump() {
|
| 4239 |
+
print 'DUMP #'.(phpQuery::$dumpCount++).' ';
|
| 4240 |
+
$debug = phpQuery::$debug;
|
| 4241 |
+
phpQuery::$debug = false;
|
| 4242 |
+
// print __FILE__.':'.__LINE__."\n";
|
| 4243 |
+
var_dump($this->htmlOuter());
|
| 4244 |
+
return $this;
|
| 4245 |
+
}
|
| 4246 |
+
public function dumpWhois() {
|
| 4247 |
+
print 'DUMP #'.(phpQuery::$dumpCount++).' ';
|
| 4248 |
+
$debug = phpQuery::$debug;
|
| 4249 |
+
phpQuery::$debug = false;
|
| 4250 |
+
// print __FILE__.':'.__LINE__."\n";
|
| 4251 |
+
var_dump('whois', $this->whois());
|
| 4252 |
+
phpQuery::$debug = $debug;
|
| 4253 |
+
return $this;
|
| 4254 |
+
}
|
| 4255 |
+
public function dumpLength() {
|
| 4256 |
+
print 'DUMP #'.(phpQuery::$dumpCount++).' ';
|
| 4257 |
+
$debug = phpQuery::$debug;
|
| 4258 |
+
phpQuery::$debug = false;
|
| 4259 |
+
// print __FILE__.':'.__LINE__."\n";
|
| 4260 |
+
var_dump('length', $this->length());
|
| 4261 |
+
phpQuery::$debug = $debug;
|
| 4262 |
+
return $this;
|
| 4263 |
+
}
|
| 4264 |
+
public function dumpTree($html = true, $title = true) {
|
| 4265 |
+
$output = $title
|
| 4266 |
+
? 'DUMP #'.(phpQuery::$dumpCount++)." \n" : '';
|
| 4267 |
+
$debug = phpQuery::$debug;
|
| 4268 |
+
phpQuery::$debug = false;
|
| 4269 |
+
foreach($this->stack() as $node)
|
| 4270 |
+
$output .= $this->__dumpTree($node);
|
| 4271 |
+
phpQuery::$debug = $debug;
|
| 4272 |
+
print $html
|
| 4273 |
+
? nl2br(str_replace(' ', ' ', $output))
|
| 4274 |
+
: $output;
|
| 4275 |
+
return $this;
|
| 4276 |
+
}
|
| 4277 |
+
private function __dumpTree($node, $intend = 0) {
|
| 4278 |
+
$whois = $this->whois($node);
|
| 4279 |
+
$return = '';
|
| 4280 |
+
if ($whois)
|
| 4281 |
+
$return .= str_repeat(' - ', $intend).$whois."\n";
|
| 4282 |
+
if (isset($node->childNodes))
|
| 4283 |
+
foreach($node->childNodes as $chNode)
|
| 4284 |
+
$return .= $this->__dumpTree($chNode, $intend+1);
|
| 4285 |
+
return $return;
|
| 4286 |
+
}
|
| 4287 |
+
/**
|
| 4288 |
+
* Dump htmlOuter and stop script execution. Usefull for debugging.
|
| 4289 |
+
*
|
| 4290 |
+
*/
|
| 4291 |
+
public function dumpDie() {
|
| 4292 |
+
print __FILE__.':'.__LINE__;
|
| 4293 |
+
var_dump($this->htmlOuter());
|
| 4294 |
+
die();
|
| 4295 |
+
}
|
| 4296 |
+
}
|
| 4297 |
+
|
| 4298 |
+
|
| 4299 |
+
// -- Multibyte Compatibility functions ---------------------------------------
|
| 4300 |
+
// http://svn.iphonewebdev.com/lace/lib/mb_compat.php
|
| 4301 |
+
|
| 4302 |
+
/**
|
| 4303 |
+
* mb_internal_encoding()
|
| 4304 |
+
*
|
| 4305 |
+
* Included for mbstring pseudo-compatability.
|
| 4306 |
+
*/
|
| 4307 |
+
if (!function_exists('mb_internal_encoding'))
|
| 4308 |
+
{
|
| 4309 |
+
function mb_internal_encoding($enc) {return true; }
|
| 4310 |
+
}
|
| 4311 |
+
|
| 4312 |
+
/**
|
| 4313 |
+
* mb_regex_encoding()
|
| 4314 |
+
*
|
| 4315 |
+
* Included for mbstring pseudo-compatability.
|
| 4316 |
+
*/
|
| 4317 |
+
if (!function_exists('mb_regex_encoding'))
|
| 4318 |
+
{
|
| 4319 |
+
function mb_regex_encoding($enc) {return true; }
|
| 4320 |
+
}
|
| 4321 |
+
|
| 4322 |
+
/**
|
| 4323 |
+
* mb_strlen()
|
| 4324 |
+
*
|
| 4325 |
+
* Included for mbstring pseudo-compatability.
|
| 4326 |
+
*/
|
| 4327 |
+
if (!function_exists('mb_strlen'))
|
| 4328 |
+
{
|
| 4329 |
+
function mb_strlen($str)
|
| 4330 |
+
{
|
| 4331 |
+
return strlen($str);
|
| 4332 |
+
}
|
| 4333 |
+
}
|
| 4334 |
+
|
| 4335 |
+
/**
|
| 4336 |
+
* mb_strpos()
|
| 4337 |
+
*
|
| 4338 |
+
* Included for mbstring pseudo-compatability.
|
| 4339 |
+
*/
|
| 4340 |
+
if (!function_exists('mb_strpos'))
|
| 4341 |
+
{
|
| 4342 |
+
function mb_strpos($haystack, $needle, $offset=0)
|
| 4343 |
+
{
|
| 4344 |
+
return strpos($haystack, $needle, $offset);
|
| 4345 |
+
}
|
| 4346 |
+
}
|
| 4347 |
+
/**
|
| 4348 |
+
* mb_stripos()
|
| 4349 |
+
*
|
| 4350 |
+
* Included for mbstring pseudo-compatability.
|
| 4351 |
+
*/
|
| 4352 |
+
if (!function_exists('mb_stripos'))
|
| 4353 |
+
{
|
| 4354 |
+
function mb_stripos($haystack, $needle, $offset=0)
|
| 4355 |
+
{
|
| 4356 |
+
return stripos($haystack, $needle, $offset);
|
| 4357 |
+
}
|
| 4358 |
+
}
|
| 4359 |
+
|
| 4360 |
+
/**
|
| 4361 |
+
* mb_substr()
|
| 4362 |
+
*
|
| 4363 |
+
* Included for mbstring pseudo-compatability.
|
| 4364 |
+
*/
|
| 4365 |
+
if (!function_exists('mb_substr'))
|
| 4366 |
+
{
|
| 4367 |
+
function mb_substr($str, $start, $length=0)
|
| 4368 |
+
{
|
| 4369 |
+
return substr($str, $start, $length);
|
| 4370 |
+
}
|
| 4371 |
+
}
|
| 4372 |
+
|
| 4373 |
+
/**
|
| 4374 |
+
* mb_substr_count()
|
| 4375 |
+
*
|
| 4376 |
+
* Included for mbstring pseudo-compatability.
|
| 4377 |
+
*/
|
| 4378 |
+
if (!function_exists('mb_substr_count'))
|
| 4379 |
+
{
|
| 4380 |
+
function mb_substr_count($haystack, $needle)
|
| 4381 |
+
{
|
| 4382 |
+
return substr_count($haystack, $needle);
|
| 4383 |
+
}
|
| 4384 |
+
}
|
| 4385 |
+
|
| 4386 |
+
|
| 4387 |
+
/**
|
| 4388 |
+
* Static namespace for phpQuery functions.
|
| 4389 |
+
*
|
| 4390 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 4391 |
+
* @package phpQuery
|
| 4392 |
+
*/
|
| 4393 |
+
abstract class phpQuery {
|
| 4394 |
+
/**
|
| 4395 |
+
* XXX: Workaround for mbstring problems
|
| 4396 |
+
*
|
| 4397 |
+
* @var bool
|
| 4398 |
+
*/
|
| 4399 |
+
public static $mbstringSupport = true;
|
| 4400 |
+
public static $debug = false;
|
| 4401 |
+
public static $documents = array();
|
| 4402 |
+
public static $defaultDocumentID = null;
|
| 4403 |
+
// public static $defaultDoctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"';
|
| 4404 |
+
/**
|
| 4405 |
+
* Applies only to HTML.
|
| 4406 |
+
*
|
| 4407 |
+
* @var unknown_type
|
| 4408 |
+
*/
|
| 4409 |
+
public static $defaultDoctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
| 4410 |
+
"http://www.w3.org/TR/html4/loose.dtd">';
|
| 4411 |
+
public static $defaultCharset = 'UTF-8';
|
| 4412 |
+
/**
|
| 4413 |
+
* Static namespace for plugins.
|
| 4414 |
+
*
|
| 4415 |
+
* @var object
|
| 4416 |
+
*/
|
| 4417 |
+
public static $plugins = array();
|
| 4418 |
+
/**
|
| 4419 |
+
* List of loaded plugins.
|
| 4420 |
+
*
|
| 4421 |
+
* @var unknown_type
|
| 4422 |
+
*/
|
| 4423 |
+
public static $pluginsLoaded = array();
|
| 4424 |
+
public static $pluginsMethods = array();
|
| 4425 |
+
public static $pluginsStaticMethods = array();
|
| 4426 |
+
public static $extendMethods = array();
|
| 4427 |
+
/**
|
| 4428 |
+
* @TODO implement
|
| 4429 |
+
*/
|
| 4430 |
+
public static $extendStaticMethods = array();
|
| 4431 |
+
/**
|
| 4432 |
+
* Hosts allowed for AJAX connections.
|
| 4433 |
+
* Dot '.' means $_SERVER['HTTP_HOST'] (if any).
|
| 4434 |
+
*
|
| 4435 |
+
* @var array
|
| 4436 |
+
*/
|
| 4437 |
+
public static $ajaxAllowedHosts = array(
|
| 4438 |
+
'.'
|
| 4439 |
+
);
|
| 4440 |
+
/**
|
| 4441 |
+
* AJAX settings.
|
| 4442 |
+
*
|
| 4443 |
+
* @var array
|
| 4444 |
+
* XXX should it be static or not ?
|
| 4445 |
+
*/
|
| 4446 |
+
public static $ajaxSettings = array(
|
| 4447 |
+
'url' => '',//TODO
|
| 4448 |
+
'global' => true,
|
| 4449 |
+
'type' => "GET",
|
| 4450 |
+
'timeout' => null,
|
| 4451 |
+
'contentType' => "application/x-www-form-urlencoded",
|
| 4452 |
+
'processData' => true,
|
| 4453 |
+
// 'async' => true,
|
| 4454 |
+
'data' => null,
|
| 4455 |
+
'username' => null,
|
| 4456 |
+
'password' => null,
|
| 4457 |
+
'accepts' => array(
|
| 4458 |
+
'xml' => "application/xml, text/xml",
|
| 4459 |
+
'html' => "text/html",
|
| 4460 |
+
'script' => "text/javascript, application/javascript",
|
| 4461 |
+
'json' => "application/json, text/javascript",
|
| 4462 |
+
'text' => "text/plain",
|
| 4463 |
+
'_default' => "*/*"
|
| 4464 |
+
)
|
| 4465 |
+
);
|
| 4466 |
+
public static $lastModified = null;
|
| 4467 |
+
public static $active = 0;
|
| 4468 |
+
public static $dumpCount = 0;
|
| 4469 |
+
/**
|
| 4470 |
+
* Multi-purpose function.
|
| 4471 |
+
* Use pq() as shortcut.
|
| 4472 |
+
*
|
| 4473 |
+
* In below examples, $pq is any result of pq(); function.
|
| 4474 |
+
*
|
| 4475 |
+
* 1. Import markup into existing document (without any attaching):
|
| 4476 |
+
* - Import into selected document:
|
| 4477 |
+
* pq('<div/>') // DOESNT accept text nodes at beginning of input string !
|
| 4478 |
+
* - Import into document with ID from $pq->getDocumentID():
|
| 4479 |
+
* pq('<div/>', $pq->getDocumentID())
|
| 4480 |
+
* - Import into same document as DOMNode belongs to:
|
| 4481 |
+
* pq('<div/>', DOMNode)
|
| 4482 |
+
* - Import into document from phpQuery object:
|
| 4483 |
+
* pq('<div/>', $pq)
|
| 4484 |
+
*
|
| 4485 |
+
* 2. Run query:
|
| 4486 |
+
* - Run query on last selected document:
|
| 4487 |
+
* pq('div.myClass')
|
| 4488 |
+
* - Run query on document with ID from $pq->getDocumentID():
|
| 4489 |
+
* pq('div.myClass', $pq->getDocumentID())
|
| 4490 |
+
* - Run query on same document as DOMNode belongs to and use node(s)as root for query:
|
| 4491 |
+
* pq('div.myClass', DOMNode)
|
| 4492 |
+
* - Run query on document from phpQuery object
|
| 4493 |
+
* and use object's stack as root node(s) for query:
|
| 4494 |
+
* pq('div.myClass', $pq)
|
| 4495 |
+
*
|
| 4496 |
+
* @param string|DOMNode|DOMNodeList|array $arg1 HTML markup, CSS Selector, DOMNode or array of DOMNodes
|
| 4497 |
+
* @param string|phpQueryObject|DOMNode $context DOM ID from $pq->getDocumentID(), phpQuery object (determines also query root) or DOMNode (determines also query root)
|
| 4498 |
+
*
|
| 4499 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery|QueryTemplatesPhpQuery|false
|
| 4500 |
+
* phpQuery object or false in case of error.
|
| 4501 |
+
*/
|
| 4502 |
+
public static function pq($arg1, $context = null) {
|
| 4503 |
+
if ($arg1 instanceof DOMNODE && ! isset($context)) {
|
| 4504 |
+
foreach(phpQuery::$documents as $documentWrapper) {
|
| 4505 |
+
$compare = $arg1 instanceof DOMDocument
|
| 4506 |
+
? $arg1 : $arg1->ownerDocument;
|
| 4507 |
+
if ($documentWrapper->document->isSameNode($compare))
|
| 4508 |
+
$context = $documentWrapper->id;
|
| 4509 |
+
}
|
| 4510 |
+
}
|
| 4511 |
+
if (! $context) {
|
| 4512 |
+
$domId = self::$defaultDocumentID;
|
| 4513 |
+
if (! $domId)
|
| 4514 |
+
throw new Exception("Can't use last created DOM, because there isn't any. Use phpQuery::newDocument() first.");
|
| 4515 |
+
// } else if (is_object($context) && ($context instanceof PHPQUERY || is_subclass_of($context, 'phpQueryObject')))
|
| 4516 |
+
} else if (is_object($context) && $context instanceof phpQueryObject)
|
| 4517 |
+
$domId = $context->getDocumentID();
|
| 4518 |
+
else if ($context instanceof DOMDOCUMENT) {
|
| 4519 |
+
$domId = self::getDocumentID($context);
|
| 4520 |
+
if (! $domId) {
|
| 4521 |
+
//throw new Exception('Orphaned DOMDocument');
|
| 4522 |
+
$domId = self::newDocument($context)->getDocumentID();
|
| 4523 |
+
}
|
| 4524 |
+
} else if ($context instanceof DOMNODE) {
|
| 4525 |
+
$domId = self::getDocumentID($context);
|
| 4526 |
+
if (! $domId) {
|
| 4527 |
+
throw new Exception('Orphaned DOMNode');
|
| 4528 |
+
// $domId = self::newDocument($context->ownerDocument);
|
| 4529 |
+
}
|
| 4530 |
+
} else
|
| 4531 |
+
$domId = $context;
|
| 4532 |
+
if ($arg1 instanceof phpQueryObject) {
|
| 4533 |
+
// if (is_object($arg1) && (get_class($arg1) == 'phpQueryObject' || $arg1 instanceof PHPQUERY || is_subclass_of($arg1, 'phpQueryObject'))) {
|
| 4534 |
+
/**
|
| 4535 |
+
* Return $arg1 or import $arg1 stack if document differs:
|
| 4536 |
+
* pq(pq('<div/>'))
|
| 4537 |
+
*/
|
| 4538 |
+
if ($arg1->getDocumentID() == $domId)
|
| 4539 |
+
return $arg1;
|
| 4540 |
+
$class = get_class($arg1);
|
| 4541 |
+
// support inheritance by passing old object to overloaded constructor
|
| 4542 |
+
$phpQuery = $class != 'phpQuery'
|
| 4543 |
+
? new $class($arg1, $domId)
|
| 4544 |
+
: new phpQueryObject($domId);
|
| 4545 |
+
$phpQuery->elements = array();
|
| 4546 |
+
foreach($arg1->elements as $node)
|
| 4547 |
+
$phpQuery->elements[] = $phpQuery->document->importNode($node, true);
|
| 4548 |
+
return $phpQuery;
|
| 4549 |
+
} else if ($arg1 instanceof DOMNODE || (is_array($arg1) && isset($arg1[0]) && $arg1[0] instanceof DOMNODE)) {
|
| 4550 |
+
/*
|
| 4551 |
+
* Wrap DOM nodes with phpQuery object, import into document when needed:
|
| 4552 |
+
* pq(array($domNode1, $domNode2))
|
| 4553 |
+
*/
|
| 4554 |
+
$phpQuery = new phpQueryObject($domId);
|
| 4555 |
+
if (!($arg1 instanceof DOMNODELIST) && ! is_array($arg1))
|
| 4556 |
+
$arg1 = array($arg1);
|
| 4557 |
+
$phpQuery->elements = array();
|
| 4558 |
+
foreach($arg1 as $node) {
|
| 4559 |
+
$sameDocument = $node->ownerDocument instanceof DOMDOCUMENT
|
| 4560 |
+
&& ! $node->ownerDocument->isSameNode($phpQuery->document);
|
| 4561 |
+
$phpQuery->elements[] = $sameDocument
|
| 4562 |
+
? $phpQuery->document->importNode($node, true)
|
| 4563 |
+
: $node;
|
| 4564 |
+
}
|
| 4565 |
+
return $phpQuery;
|
| 4566 |
+
} else if (self::isMarkup($arg1)) {
|
| 4567 |
+
/**
|
| 4568 |
+
* Import HTML:
|
| 4569 |
+
* pq('<div/>')
|
| 4570 |
+
*/
|
| 4571 |
+
$phpQuery = new phpQueryObject($domId);
|
| 4572 |
+
return $phpQuery->newInstance(
|
| 4573 |
+
$phpQuery->documentWrapper->import($arg1)
|
| 4574 |
+
);
|
| 4575 |
+
} else {
|
| 4576 |
+
/**
|
| 4577 |
+
* Run CSS query:
|
| 4578 |
+
* pq('div.myClass')
|
| 4579 |
+
*/
|
| 4580 |
+
$phpQuery = new phpQueryObject($domId);
|
| 4581 |
+
// if ($context && ($context instanceof PHPQUERY || is_subclass_of($context, 'phpQueryObject')))
|
| 4582 |
+
if ($context && $context instanceof phpQueryObject)
|
| 4583 |
+
$phpQuery->elements = $context->elements;
|
| 4584 |
+
else if ($context && $context instanceof DOMNODELIST) {
|
| 4585 |
+
$phpQuery->elements = array();
|
| 4586 |
+
foreach($context as $node)
|
| 4587 |
+
$phpQuery->elements[] = $node;
|
| 4588 |
+
} else if ($context && $context instanceof DOMNODE)
|
| 4589 |
+
$phpQuery->elements = array($context);
|
| 4590 |
+
return $phpQuery->find($arg1);
|
| 4591 |
+
}
|
| 4592 |
+
}
|
| 4593 |
+
/**
|
| 4594 |
+
* Sets default document to $id. Document has to be loaded prior
|
| 4595 |
+
* to using this method.
|
| 4596 |
+
* $id can be retrived via getDocumentID() or getDocumentIDRef().
|
| 4597 |
+
*
|
| 4598 |
+
* @param unknown_type $id
|
| 4599 |
+
*/
|
| 4600 |
+
public static function selectDocument($id) {
|
| 4601 |
+
$id = self::getDocumentID($id);
|
| 4602 |
+
self::debug("Selecting document '$id' as default one");
|
| 4603 |
+
self::$defaultDocumentID = self::getDocumentID($id);
|
| 4604 |
+
}
|
| 4605 |
+
/**
|
| 4606 |
+
* Returns document with id $id or last used as phpQueryObject.
|
| 4607 |
+
* $id can be retrived via getDocumentID() or getDocumentIDRef().
|
| 4608 |
+
* Chainable.
|
| 4609 |
+
*
|
| 4610 |
+
* @see phpQuery::selectDocument()
|
| 4611 |
+
* @param unknown_type $id
|
| 4612 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4613 |
+
*/
|
| 4614 |
+
public static function getDocument($id = null) {
|
| 4615 |
+
if ($id)
|
| 4616 |
+
phpQuery::selectDocument($id);
|
| 4617 |
+
else
|
| 4618 |
+
$id = phpQuery::$defaultDocumentID;
|
| 4619 |
+
return new phpQueryObject($id);
|
| 4620 |
+
}
|
| 4621 |
+
/**
|
| 4622 |
+
* Creates new document from markup.
|
| 4623 |
+
* Chainable.
|
| 4624 |
+
*
|
| 4625 |
+
* @param unknown_type $markup
|
| 4626 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4627 |
+
*/
|
| 4628 |
+
public static function newDocument($markup = null, $contentType = null) {
|
| 4629 |
+
if (! $markup)
|
| 4630 |
+
$markup = '';
|
| 4631 |
+
$documentID = phpQuery::createDocumentWrapper($markup, $contentType);
|
| 4632 |
+
return new phpQueryObject($documentID);
|
| 4633 |
+
}
|
| 4634 |
+
/**
|
| 4635 |
+
* Creates new document from markup.
|
| 4636 |
+
* Chainable.
|
| 4637 |
+
*
|
| 4638 |
+
* @param unknown_type $markup
|
| 4639 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4640 |
+
*/
|
| 4641 |
+
public static function newDocumentHTML($markup = null, $charset = null) {
|
| 4642 |
+
$contentType = $charset
|
| 4643 |
+
? ";charset=$charset"
|
| 4644 |
+
: '';
|
| 4645 |
+
return self::newDocument($markup, "text/html{$contentType}");
|
| 4646 |
+
}
|
| 4647 |
+
/**
|
| 4648 |
+
* Creates new document from markup.
|
| 4649 |
+
* Chainable.
|
| 4650 |
+
*
|
| 4651 |
+
* @param unknown_type $markup
|
| 4652 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4653 |
+
*/
|
| 4654 |
+
public static function newDocumentXML($markup = null, $charset = null) {
|
| 4655 |
+
$contentType = $charset
|
| 4656 |
+
? ";charset=$charset"
|
| 4657 |
+
: '';
|
| 4658 |
+
return self::newDocument($markup, "text/xml{$contentType}");
|
| 4659 |
+
}
|
| 4660 |
+
/**
|
| 4661 |
+
* Creates new document from markup.
|
| 4662 |
+
* Chainable.
|
| 4663 |
+
*
|
| 4664 |
+
* @param unknown_type $markup
|
| 4665 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4666 |
+
*/
|
| 4667 |
+
public static function newDocumentXHTML($markup = null, $charset = null) {
|
| 4668 |
+
$contentType = $charset
|
| 4669 |
+
? ";charset=$charset"
|
| 4670 |
+
: '';
|
| 4671 |
+
return self::newDocument($markup, "application/xhtml+xml{$contentType}");
|
| 4672 |
+
}
|
| 4673 |
+
/**
|
| 4674 |
+
* Creates new document from markup.
|
| 4675 |
+
* Chainable.
|
| 4676 |
+
*
|
| 4677 |
+
* @param unknown_type $markup
|
| 4678 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4679 |
+
*/
|
| 4680 |
+
public static function newDocumentPHP($markup = null, $contentType = "text/html") {
|
| 4681 |
+
// TODO pass charset to phpToMarkup if possible (use DOMDocumentWrapper function)
|
| 4682 |
+
$markup = phpQuery::phpToMarkup($markup, self::$defaultCharset);
|
| 4683 |
+
return self::newDocument($markup, $contentType);
|
| 4684 |
+
}
|
| 4685 |
+
public static function phpToMarkup($php, $charset = 'utf-8') {
|
| 4686 |
+
$regexes = array(
|
| 4687 |
+
'@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(\')([^\']*)<'.'?php?(.*?)(?:\\?>)([^\']*)\'@s',
|
| 4688 |
+
'@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(")([^"]*)<'.'?php?(.*?)(?:\\?>)([^"]*)"@s',
|
| 4689 |
+
);
|
| 4690 |
+
foreach($regexes as $regex)
|
| 4691 |
+
while (preg_match($regex, $php, $matches)) {
|
| 4692 |
+
$php = preg_replace_callback(
|
| 4693 |
+
$regex,
|
| 4694 |
+
// create_function('$m, $charset = "'.$charset.'"',
|
| 4695 |
+
// 'return $m[1].$m[2]
|
| 4696 |
+
// .htmlspecialchars("<"."?php".$m[4]."?".">", ENT_QUOTES|ENT_NOQUOTES, $charset)
|
| 4697 |
+
// .$m[5].$m[2];'
|
| 4698 |
+
// ),
|
| 4699 |
+
array('phpQuery', '_phpToMarkupCallback'),
|
| 4700 |
+
$php
|
| 4701 |
+
);
|
| 4702 |
+
}
|
| 4703 |
+
$regex = '@(^|>[^<]*)+?(<\?php(.*?)(\?>))@s';
|
| 4704 |
+
//preg_match_all($regex, $php, $matches);
|
| 4705 |
+
//var_dump($matches);
|
| 4706 |
+
$php = preg_replace($regex, '\\1<php><!-- \\3 --></php>', $php);
|
| 4707 |
+
return $php;
|
| 4708 |
+
}
|
| 4709 |
+
public static function _phpToMarkupCallback($php, $charset = 'utf-8') {
|
| 4710 |
+
return $m[1].$m[2]
|
| 4711 |
+
.htmlspecialchars("<"."?php".$m[4]."?".">", ENT_QUOTES|ENT_NOQUOTES, $charset)
|
| 4712 |
+
.$m[5].$m[2];
|
| 4713 |
+
}
|
| 4714 |
+
public static function _markupToPHPCallback($m) {
|
| 4715 |
+
return "<"."?php ".htmlspecialchars_decode($m[1])." ?".">";
|
| 4716 |
+
}
|
| 4717 |
+
/**
|
| 4718 |
+
* Converts document markup containing PHP code generated by phpQuery::php()
|
| 4719 |
+
* into valid (executable) PHP code syntax.
|
| 4720 |
+
*
|
| 4721 |
+
* @param string|phpQueryObject $content
|
| 4722 |
+
* @return string PHP code.
|
| 4723 |
+
*/
|
| 4724 |
+
public static function markupToPHP($content) {
|
| 4725 |
+
if ($content instanceof phpQueryObject)
|
| 4726 |
+
$content = $content->markupOuter();
|
| 4727 |
+
/* <php>...</php> to <?php...? > */
|
| 4728 |
+
$content = preg_replace_callback(
|
| 4729 |
+
'@<php>\s*<!--(.*?)-->\s*</php>@s',
|
| 4730 |
+
// create_function('$m',
|
| 4731 |
+
// 'return "<'.'?php ".htmlspecialchars_decode($m[1])." ?'.'>";'
|
| 4732 |
+
// ),
|
| 4733 |
+
array('phpQuery', '_markupToPHPCallback'),
|
| 4734 |
+
$content
|
| 4735 |
+
);
|
| 4736 |
+
/* <node attr='< ?php ? >'> extra space added to save highlighters */
|
| 4737 |
+
$regexes = array(
|
| 4738 |
+
'@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(\')([^\']*)(?:<|%3C)\\?(?:php)?(.*?)(?:\\?(?:>|%3E))([^\']*)\'@s',
|
| 4739 |
+
'@(<(?!\\?)(?:[^>]|\\?>)+\\w+\\s*=\\s*)(")([^"]*)(?:<|%3C)\\?(?:php)?(.*?)(?:\\?(?:>|%3E))([^"]*)"@s',
|
| 4740 |
+
);
|
| 4741 |
+
foreach($regexes as $regex)
|
| 4742 |
+
while (preg_match($regex, $content))
|
| 4743 |
+
$content = preg_replace_callback(
|
| 4744 |
+
$regex,
|
| 4745 |
+
create_function('$m',
|
| 4746 |
+
'return $m[1].$m[2].$m[3]."<?php "
|
| 4747 |
+
.str_replace(
|
| 4748 |
+
array("%20", "%3E", "%09", " ", "	", "%7B", "%24", "%7D", "%22", "%5B", "%5D"),
|
| 4749 |
+
array(" ", ">", " ", "\n", " ", "{", "$", "}", \'"\', "[", "]"),
|
| 4750 |
+
htmlspecialchars_decode($m[4])
|
| 4751 |
+
)
|
| 4752 |
+
." ?>".$m[5].$m[2];'
|
| 4753 |
+
),
|
| 4754 |
+
$content
|
| 4755 |
+
);
|
| 4756 |
+
return $content;
|
| 4757 |
+
}
|
| 4758 |
+
/**
|
| 4759 |
+
* Creates new document from file $file.
|
| 4760 |
+
* Chainable.
|
| 4761 |
+
*
|
| 4762 |
+
* @param string $file URLs allowed. See File wrapper page at php.net for more supported sources.
|
| 4763 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4764 |
+
*/
|
| 4765 |
+
public static function newDocumentFile($file, $contentType = null) {
|
| 4766 |
+
$documentID = self::createDocumentWrapper(
|
| 4767 |
+
file_get_contents($file), $contentType
|
| 4768 |
+
);
|
| 4769 |
+
return new phpQueryObject($documentID);
|
| 4770 |
+
}
|
| 4771 |
+
/**
|
| 4772 |
+
* Creates new document from markup.
|
| 4773 |
+
* Chainable.
|
| 4774 |
+
*
|
| 4775 |
+
* @param unknown_type $markup
|
| 4776 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4777 |
+
*/
|
| 4778 |
+
public static function newDocumentFileHTML($file, $charset = null) {
|
| 4779 |
+
$contentType = $charset
|
| 4780 |
+
? ";charset=$charset"
|
| 4781 |
+
: '';
|
| 4782 |
+
return self::newDocumentFile($file, "text/html{$contentType}");
|
| 4783 |
+
}
|
| 4784 |
+
/**
|
| 4785 |
+
* Creates new document from markup.
|
| 4786 |
+
* Chainable.
|
| 4787 |
+
*
|
| 4788 |
+
* @param unknown_type $markup
|
| 4789 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4790 |
+
*/
|
| 4791 |
+
public static function newDocumentFileXML($file, $charset = null) {
|
| 4792 |
+
$contentType = $charset
|
| 4793 |
+
? ";charset=$charset"
|
| 4794 |
+
: '';
|
| 4795 |
+
return self::newDocumentFile($file, "text/xml{$contentType}");
|
| 4796 |
+
}
|
| 4797 |
+
/**
|
| 4798 |
+
* Creates new document from markup.
|
| 4799 |
+
* Chainable.
|
| 4800 |
+
*
|
| 4801 |
+
* @param unknown_type $markup
|
| 4802 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4803 |
+
*/
|
| 4804 |
+
public static function newDocumentFileXHTML($file, $charset = null) {
|
| 4805 |
+
$contentType = $charset
|
| 4806 |
+
? ";charset=$charset"
|
| 4807 |
+
: '';
|
| 4808 |
+
return self::newDocumentFile($file, "application/xhtml+xml{$contentType}");
|
| 4809 |
+
}
|
| 4810 |
+
/**
|
| 4811 |
+
* Creates new document from markup.
|
| 4812 |
+
* Chainable.
|
| 4813 |
+
*
|
| 4814 |
+
* @param unknown_type $markup
|
| 4815 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4816 |
+
*/
|
| 4817 |
+
public static function newDocumentFilePHP($file, $contentType = null) {
|
| 4818 |
+
return self::newDocumentPHP(file_get_contents($file), $contentType);
|
| 4819 |
+
}
|
| 4820 |
+
/**
|
| 4821 |
+
* Reuses existing DOMDocument object.
|
| 4822 |
+
* Chainable.
|
| 4823 |
+
*
|
| 4824 |
+
* @param $document DOMDocument
|
| 4825 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 4826 |
+
* @TODO support DOMDocument
|
| 4827 |
+
*/
|
| 4828 |
+
public static function loadDocument($document) {
|
| 4829 |
+
// TODO
|
| 4830 |
+
die('TODO loadDocument');
|
| 4831 |
+
}
|
| 4832 |
+
/**
|
| 4833 |
+
* Enter description here...
|
| 4834 |
+
*
|
| 4835 |
+
* @param unknown_type $html
|
| 4836 |
+
* @param unknown_type $domId
|
| 4837 |
+
* @return unknown New DOM ID
|
| 4838 |
+
* @todo support PHP tags in input
|
| 4839 |
+
* @todo support passing DOMDocument object from self::loadDocument
|
| 4840 |
+
*/
|
| 4841 |
+
protected static function createDocumentWrapper($html, $contentType = null, $documentID = null) {
|
| 4842 |
+
if (function_exists('domxml_open_mem'))
|
| 4843 |
+
throw new Exception("Old PHP4 DOM XML extension detected. phpQuery won't work until this extension is enabled.");
|
| 4844 |
+
// $id = $documentID
|
| 4845 |
+
// ? $documentID
|
| 4846 |
+
// : md5(microtime());
|
| 4847 |
+
$document = null;
|
| 4848 |
+
if ($html instanceof DOMDOCUMENT) {
|
| 4849 |
+
if (self::getDocumentID($html)) {
|
| 4850 |
+
// document already exists in phpQuery::$documents, make a copy
|
| 4851 |
+
$document = clone $html;
|
| 4852 |
+
} else {
|
| 4853 |
+
// new document, add it to phpQuery::$documents
|
| 4854 |
+
$wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
|
| 4855 |
+
}
|
| 4856 |
+
} else {
|
| 4857 |
+
$wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
|
| 4858 |
+
}
|
| 4859 |
+
// $wrapper->id = $id;
|
| 4860 |
+
// bind document
|
| 4861 |
+
phpQuery::$documents[$wrapper->id] = $wrapper;
|
| 4862 |
+
// remember last loaded document
|
| 4863 |
+
phpQuery::selectDocument($wrapper->id);
|
| 4864 |
+
return $wrapper->id;
|
| 4865 |
+
}
|
| 4866 |
+
/**
|
| 4867 |
+
* Extend class namespace.
|
| 4868 |
+
*
|
| 4869 |
+
* @param string|array $target
|
| 4870 |
+
* @param array $source
|
| 4871 |
+
* @TODO support string $source
|
| 4872 |
+
* @return unknown_type
|
| 4873 |
+
*/
|
| 4874 |
+
public static function extend($target, $source) {
|
| 4875 |
+
switch($target) {
|
| 4876 |
+
case 'phpQueryObject':
|
| 4877 |
+
$targetRef = &self::$extendMethods;
|
| 4878 |
+
$targetRef2 = &self::$pluginsMethods;
|
| 4879 |
+
break;
|
| 4880 |
+
case 'phpQuery':
|
| 4881 |
+
$targetRef = &self::$extendStaticMethods;
|
| 4882 |
+
$targetRef2 = &self::$pluginsStaticMethods;
|
| 4883 |
+
break;
|
| 4884 |
+
default:
|
| 4885 |
+
throw new Exception("Unsupported \$target type");
|
| 4886 |
+
}
|
| 4887 |
+
if (is_string($source))
|
| 4888 |
+
$source = array($source => $source);
|
| 4889 |
+
foreach($source as $method => $callback) {
|
| 4890 |
+
if (isset($targetRef[$method])) {
|
| 4891 |
+
// throw new Exception
|
| 4892 |
+
self::debug("Duplicate method '{$method}', can\'t extend '{$target}'");
|
| 4893 |
+
continue;
|
| 4894 |
+
}
|
| 4895 |
+
if (isset($targetRef2[$method])) {
|
| 4896 |
+
// throw new Exception
|
| 4897 |
+
self::debug("Duplicate method '{$method}' from plugin '{$targetRef2[$method]}',"
|
| 4898 |
+
." can\'t extend '{$target}'");
|
| 4899 |
+
continue;
|
| 4900 |
+
}
|
| 4901 |
+
$targetRef[$method] = $callback;
|
| 4902 |
+
}
|
| 4903 |
+
return true;
|
| 4904 |
+
}
|
| 4905 |
+
/**
|
| 4906 |
+
* Extend phpQuery with $class from $file.
|
| 4907 |
+
*
|
| 4908 |
+
* @param string $class Extending class name. Real class name can be prepended phpQuery_.
|
| 4909 |
+
* @param string $file Filename to include. Defaults to "{$class}.php".
|
| 4910 |
+
*/
|
| 4911 |
+
public static function plugin($class, $file = null) {
|
| 4912 |
+
// TODO $class checked agains phpQuery_$class
|
| 4913 |
+
// if (strpos($class, 'phpQuery') === 0)
|
| 4914 |
+
// $class = substr($class, 8);
|
| 4915 |
+
if (in_array($class, self::$pluginsLoaded))
|
| 4916 |
+
return true;
|
| 4917 |
+
if (! $file)
|
| 4918 |
+
$file = $class.'.php';
|
| 4919 |
+
$objectClassExists = class_exists('phpQueryObjectPlugin_'.$class);
|
| 4920 |
+
$staticClassExists = class_exists('phpQueryPlugin_'.$class);
|
| 4921 |
+
if (! $objectClassExists && ! $staticClassExists)
|
| 4922 |
+
require_once($file);
|
| 4923 |
+
self::$pluginsLoaded[] = $class;
|
| 4924 |
+
// static methods
|
| 4925 |
+
if (class_exists('phpQueryPlugin_'.$class)) {
|
| 4926 |
+
$realClass = 'phpQueryPlugin_'.$class;
|
| 4927 |
+
$vars = get_class_vars($realClass);
|
| 4928 |
+
$loop = isset($vars['phpQueryMethods'])
|
| 4929 |
+
&& ! is_null($vars['phpQueryMethods'])
|
| 4930 |
+
? $vars['phpQueryMethods']
|
| 4931 |
+
: get_class_methods($realClass);
|
| 4932 |
+
foreach($loop as $method) {
|
| 4933 |
+
if ($method == '__initialize')
|
| 4934 |
+
continue;
|
| 4935 |
+
if (! is_callable(array($realClass, $method)))
|
| 4936 |
+
continue;
|
| 4937 |
+
if (isset(self::$pluginsStaticMethods[$method])) {
|
| 4938 |
+
throw new Exception("Duplicate method '{$method}' from plugin '{$c}' conflicts with same method from plugin '".self::$pluginsStaticMethods[$method]."'");
|
| 4939 |
+
return;
|
| 4940 |
+
}
|
| 4941 |
+
self::$pluginsStaticMethods[$method] = $class;
|
| 4942 |
+
}
|
| 4943 |
+
if (method_exists($realClass, '__initialize'))
|
| 4944 |
+
call_user_func_array(array($realClass, '__initialize'), array());
|
| 4945 |
+
}
|
| 4946 |
+
// object methods
|
| 4947 |
+
if (class_exists('phpQueryObjectPlugin_'.$class)) {
|
| 4948 |
+
$realClass = 'phpQueryObjectPlugin_'.$class;
|
| 4949 |
+
$vars = get_class_vars($realClass);
|
| 4950 |
+
$loop = isset($vars['phpQueryMethods'])
|
| 4951 |
+
&& ! is_null($vars['phpQueryMethods'])
|
| 4952 |
+
? $vars['phpQueryMethods']
|
| 4953 |
+
: get_class_methods($realClass);
|
| 4954 |
+
foreach($loop as $method) {
|
| 4955 |
+
if (! is_callable(array($realClass, $method)))
|
| 4956 |
+
continue;
|
| 4957 |
+
if (isset(self::$pluginsMethods[$method])) {
|
| 4958 |
+
throw new Exception("Duplicate method '{$method}' from plugin '{$c}' conflicts with same method from plugin '".self::$pluginsMethods[$method]."'");
|
| 4959 |
+
continue;
|
| 4960 |
+
}
|
| 4961 |
+
self::$pluginsMethods[$method] = $class;
|
| 4962 |
+
}
|
| 4963 |
+
}
|
| 4964 |
+
return true;
|
| 4965 |
+
}
|
| 4966 |
+
/**
|
| 4967 |
+
* Unloades all or specified document from memory.
|
| 4968 |
+
*
|
| 4969 |
+
* @param mixed $documentID @see phpQuery::getDocumentID() for supported types.
|
| 4970 |
+
*/
|
| 4971 |
+
public static function unloadDocuments($id = null) {
|
| 4972 |
+
if (isset($id)) {
|
| 4973 |
+
if ($id = self::getDocumentID($id))
|
| 4974 |
+
unset(phpQuery::$documents[$id]);
|
| 4975 |
+
} else {
|
| 4976 |
+
foreach(phpQuery::$documents as $k => $v) {
|
| 4977 |
+
unset(phpQuery::$documents[$k]);
|
| 4978 |
+
}
|
| 4979 |
+
}
|
| 4980 |
+
}
|
| 4981 |
+
/**
|
| 4982 |
+
* Parses phpQuery object or HTML result against PHP tags and makes them active.
|
| 4983 |
+
*
|
| 4984 |
+
* @param phpQuery|string $content
|
| 4985 |
+
* @deprecated
|
| 4986 |
+
* @return string
|
| 4987 |
+
*/
|
| 4988 |
+
public static function unsafePHPTags($content) {
|
| 4989 |
+
return self::markupToPHP($content);
|
| 4990 |
+
}
|
| 4991 |
+
public static function DOMNodeListToArray($DOMNodeList) {
|
| 4992 |
+
$array = array();
|
| 4993 |
+
if (! $DOMNodeList)
|
| 4994 |
+
return $array;
|
| 4995 |
+
foreach($DOMNodeList as $node)
|
| 4996 |
+
$array[] = $node;
|
| 4997 |
+
return $array;
|
| 4998 |
+
}
|
| 4999 |
+
/**
|
| 5000 |
+
* Checks if $input is HTML string, which has to start with '<'.
|
| 5001 |
+
*
|
| 5002 |
+
* @deprecated
|
| 5003 |
+
* @param String $input
|
| 5004 |
+
* @return Bool
|
| 5005 |
+
* @todo still used ?
|
| 5006 |
+
*/
|
| 5007 |
+
public static function isMarkup($input) {
|
| 5008 |
+
return ! is_array($input) && substr(trim($input), 0, 1) == '<';
|
| 5009 |
+
}
|
| 5010 |
+
public static function debug($text) {
|
| 5011 |
+
if (self::$debug)
|
| 5012 |
+
print var_dump($text);
|
| 5013 |
+
}
|
| 5014 |
+
/**
|
| 5015 |
+
* Make an AJAX request.
|
| 5016 |
+
*
|
| 5017 |
+
* @param array See $options http://docs.jquery.com/Ajax/jQuery.ajax#toptions
|
| 5018 |
+
* Additional options are:
|
| 5019 |
+
* 'document' - document for global events, @see phpQuery::getDocumentID()
|
| 5020 |
+
* 'referer' - implemented
|
| 5021 |
+
* 'requested_with' - TODO; not implemented (X-Requested-With)
|
| 5022 |
+
* @return Zend_Http_Client
|
| 5023 |
+
* @link http://docs.jquery.com/Ajax/jQuery.ajax
|
| 5024 |
+
*
|
| 5025 |
+
* @TODO $options['cache']
|
| 5026 |
+
* @TODO $options['processData']
|
| 5027 |
+
* @TODO $options['xhr']
|
| 5028 |
+
* @TODO $options['data'] as string
|
| 5029 |
+
* @TODO XHR interface
|
| 5030 |
+
*/
|
| 5031 |
+
public static function ajax($options = array(), $xhr = null) {
|
| 5032 |
+
$options = array_merge(
|
| 5033 |
+
self::$ajaxSettings, $options
|
| 5034 |
+
);
|
| 5035 |
+
$documentID = isset($options['document'])
|
| 5036 |
+
? self::getDocumentID($options['document'])
|
| 5037 |
+
: null;
|
| 5038 |
+
if ($xhr) {
|
| 5039 |
+
// reuse existing XHR object, but clean it up
|
| 5040 |
+
$client = $xhr;
|
| 5041 |
+
// $client->setParameterPost(null);
|
| 5042 |
+
// $client->setParameterGet(null);
|
| 5043 |
+
$client->setAuth(false);
|
| 5044 |
+
$client->setHeaders("If-Modified-Since", null);
|
| 5045 |
+
$client->setHeaders("Referer", null);
|
| 5046 |
+
$client->resetParameters();
|
| 5047 |
+
} else {
|
| 5048 |
+
// create new XHR object
|
| 5049 |
+
require_once('Zend/Http/Client.php');
|
| 5050 |
+
$client = new Zend_Http_Client();
|
| 5051 |
+
$client->setCookieJar();
|
| 5052 |
+
}
|
| 5053 |
+
if (isset($options['timeout']))
|
| 5054 |
+
$client->setConfig(array(
|
| 5055 |
+
'timeout' => $options['timeout'],
|
| 5056 |
+
));
|
| 5057 |
+
// 'maxredirects' => 0,
|
| 5058 |
+
foreach(self::$ajaxAllowedHosts as $k => $host)
|
| 5059 |
+
if ($host == '.' && isset($_SERVER['HTTP_HOST']))
|
| 5060 |
+
self::$ajaxAllowedHosts[$k] = $_SERVER['HTTP_HOST'];
|
| 5061 |
+
$host = parse_url($options['url'], PHP_URL_HOST);
|
| 5062 |
+
if (! in_array($host, self::$ajaxAllowedHosts)) {
|
| 5063 |
+
throw new Exception("Request not permitted, host '$host' not present in "
|
| 5064 |
+
."phpQuery::\$ajaxAllowedHosts");
|
| 5065 |
+
}
|
| 5066 |
+
// JSONP
|
| 5067 |
+
$jsre = "/=\\?(&|$)/";
|
| 5068 |
+
if (isset($options['dataType']) && $options['dataType'] == 'jsonp') {
|
| 5069 |
+
$jsonpCallbackParam = $options['jsonp']
|
| 5070 |
+
? $options['jsonp'] : 'callback';
|
| 5071 |
+
if (strtolower($options['type']) == 'get') {
|
| 5072 |
+
if (! preg_match($jsre, $options['url'])) {
|
| 5073 |
+
$sep = strpos($options['url'], '?')
|
| 5074 |
+
? '&' : '?';
|
| 5075 |
+
$options['url'] .= "$sep$jsonpCallbackParam=?";
|
| 5076 |
+
}
|
| 5077 |
+
} else if ($options['data']) {
|
| 5078 |
+
$jsonp = false;
|
| 5079 |
+
foreach($options['data'] as $n => $v) {
|
| 5080 |
+
if ($v == '?')
|
| 5081 |
+
$jsonp = true;
|
| 5082 |
+
}
|
| 5083 |
+
if (! $jsonp) {
|
| 5084 |
+
$options['data'][$jsonpCallbackParam] = '?';
|
| 5085 |
+
}
|
| 5086 |
+
}
|
| 5087 |
+
$options['dataType'] = 'json';
|
| 5088 |
+
}
|
| 5089 |
+
if (isset($options['dataType']) && $options['dataType'] == 'json') {
|
| 5090 |
+
$jsonpCallback = 'json_'.md5(microtime());
|
| 5091 |
+
$jsonpData = $jsonpUrl = false;
|
| 5092 |
+
if ($options['data']) {
|
| 5093 |
+
foreach($options['data'] as $n => $v) {
|
| 5094 |
+
if ($v == '?')
|
| 5095 |
+
$jsonpData = $n;
|
| 5096 |
+
}
|
| 5097 |
+
}
|
| 5098 |
+
if (preg_match($jsre, $options['url']))
|
| 5099 |
+
$jsonpUrl = true;
|
| 5100 |
+
if ($jsonpData !== false || $jsonpUrl) {
|
| 5101 |
+
// remember callback name for httpData()
|
| 5102 |
+
$options['_jsonp'] = $jsonpCallback;
|
| 5103 |
+
if ($jsonpData !== false)
|
| 5104 |
+
$options['data'][$jsonpData] = $jsonpCallback;
|
| 5105 |
+
if ($jsonpUrl)
|
| 5106 |
+
$options['url'] = preg_replace($jsre, "=$jsonpCallback\\1", $options['url']);
|
| 5107 |
+
}
|
| 5108 |
+
}
|
| 5109 |
+
$client->setUri($options['url']);
|
| 5110 |
+
$client->setMethod(strtoupper($options['type']));
|
| 5111 |
+
if (isset($options['referer']) && $options['referer'])
|
| 5112 |
+
$client->setHeaders('Referer', $options['referer']);
|
| 5113 |
+
$client->setHeaders(array(
|
| 5114 |
+
// 'content-type' => $options['contentType'],
|
| 5115 |
+
'User-Agent' => 'Mozilla/5.0 (X11; U; Linux x86; en-US; rv:1.9.0.5) Gecko'
|
| 5116 |
+
.'/2008122010 Firefox/3.0.5',
|
| 5117 |
+
// TODO custom charset
|
| 5118 |
+
'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
|
| 5119 |
+
// 'Connection' => 'keep-alive',
|
| 5120 |
+
// 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 5121 |
+
'Accept-Language' => 'en-us,en;q=0.5',
|
| 5122 |
+
));
|
| 5123 |
+
if ($options['username'])
|
| 5124 |
+
$client->setAuth($options['username'], $options['password']);
|
| 5125 |
+
if (isset($options['ifModified']) && $options['ifModified'])
|
| 5126 |
+
$client->setHeaders("If-Modified-Since",
|
| 5127 |
+
self::$lastModified
|
| 5128 |
+
? self::$lastModified
|
| 5129 |
+
: "Thu, 01 Jan 1970 00:00:00 GMT"
|
| 5130 |
+
);
|
| 5131 |
+
$client->setHeaders("Accept",
|
| 5132 |
+
isset($options['dataType'])
|
| 5133 |
+
&& isset(self::$ajaxSettings['accepts'][ $options['dataType'] ])
|
| 5134 |
+
? self::$ajaxSettings['accepts'][ $options['dataType'] ].", */*"
|
| 5135 |
+
: self::$ajaxSettings['accepts']['_default']
|
| 5136 |
+
);
|
| 5137 |
+
// TODO $options['processData']
|
| 5138 |
+
if ($options['data'] instanceof phpQueryObject) {
|
| 5139 |
+
$serialized = $options['data']->serializeArray($options['data']);
|
| 5140 |
+
$options['data'] = array();
|
| 5141 |
+
foreach($serialized as $r)
|
| 5142 |
+
$options['data'][ $r['name'] ] = $r['value'];
|
| 5143 |
+
}
|
| 5144 |
+
if (strtolower($options['type']) == 'get') {
|
| 5145 |
+
$client->setParameterGet($options['data']);
|
| 5146 |
+
} else if (strtolower($options['type']) == 'post') {
|
| 5147 |
+
$client->setEncType($options['contentType']);
|
| 5148 |
+
$client->setParameterPost($options['data']);
|
| 5149 |
+
}
|
| 5150 |
+
if (self::$active == 0 && $options['global'])
|
| 5151 |
+
phpQueryEvents::trigger($documentID, 'ajaxStart');
|
| 5152 |
+
self::$active++;
|
| 5153 |
+
// beforeSend callback
|
| 5154 |
+
if (isset($options['beforeSend']) && $options['beforeSend'])
|
| 5155 |
+
phpQuery::callbackRun($options['beforeSend'], array($client));
|
| 5156 |
+
// ajaxSend event
|
| 5157 |
+
if ($options['global'])
|
| 5158 |
+
phpQueryEvents::trigger($documentID, 'ajaxSend', array($client, $options));
|
| 5159 |
+
if (phpQuery::$debug) {
|
| 5160 |
+
self::debug("{$options['type']}: {$options['url']}\n");
|
| 5161 |
+
self::debug("Options: <pre>".var_export($options, true)."</pre>\n");
|
| 5162 |
+
// if ($client->getCookieJar())
|
| 5163 |
+
// self::debug("Cookies: <pre>".var_export($client->getCookieJar()->getMatchingCookies($options['url']), true)."</pre>\n");
|
| 5164 |
+
}
|
| 5165 |
+
// request
|
| 5166 |
+
$response = $client->request();
|
| 5167 |
+
if (phpQuery::$debug) {
|
| 5168 |
+
self::debug('Status: '.$response->getStatus().' / '.$response->getMessage());
|
| 5169 |
+
self::debug($client->getLastRequest());
|
| 5170 |
+
self::debug($response->getHeaders());
|
| 5171 |
+
}
|
| 5172 |
+
if ($response->isSuccessful()) {
|
| 5173 |
+
// XXX tempolary
|
| 5174 |
+
self::$lastModified = $response->getHeader('Last-Modified');
|
| 5175 |
+
$data = self::httpData($response->getBody(), $options['dataType'], $options);
|
| 5176 |
+
if (isset($options['success']) && $options['success'])
|
| 5177 |
+
phpQuery::callbackRun($options['success'], array($data, $response->getStatus(), $options));
|
| 5178 |
+
if ($options['global'])
|
| 5179 |
+
phpQueryEvents::trigger($documentID, 'ajaxSuccess', array($client, $options));
|
| 5180 |
+
} else {
|
| 5181 |
+
if (isset($options['error']) && $options['error'])
|
| 5182 |
+
phpQuery::callbackRun($options['error'], array($client, $response->getStatus(), $response->getMessage()));
|
| 5183 |
+
if ($options['global'])
|
| 5184 |
+
phpQueryEvents::trigger($documentID, 'ajaxError', array($client, /*$response->getStatus(),*/$response->getMessage(), $options));
|
| 5185 |
+
}
|
| 5186 |
+
if (isset($options['complete']) && $options['complete'])
|
| 5187 |
+
phpQuery::callbackRun($options['complete'], array($client, $response->getStatus()));
|
| 5188 |
+
if ($options['global'])
|
| 5189 |
+
phpQueryEvents::trigger($documentID, 'ajaxComplete', array($client, $options));
|
| 5190 |
+
if ($options['global'] && ! --self::$active)
|
| 5191 |
+
phpQueryEvents::trigger($documentID, 'ajaxStop');
|
| 5192 |
+
return $client;
|
| 5193 |
+
// if (is_null($domId))
|
| 5194 |
+
// $domId = self::$defaultDocumentID ? self::$defaultDocumentID : false;
|
| 5195 |
+
// return new phpQueryAjaxResponse($response, $domId);
|
| 5196 |
+
}
|
| 5197 |
+
protected static function httpData($data, $type, $options) {
|
| 5198 |
+
if (isset($options['dataFilter']) && $options['dataFilter'])
|
| 5199 |
+
$data = self::callbackRun($options['dataFilter'], array($data, $type));
|
| 5200 |
+
if (is_string($data)) {
|
| 5201 |
+
if ($type == "json") {
|
| 5202 |
+
if (isset($options['_jsonp']) && $options['_jsonp']) {
|
| 5203 |
+
$data = preg_replace('/^\s*\w+\((.*)\)\s*$/s', '$1', $data);
|
| 5204 |
+
}
|
| 5205 |
+
$data = self::parseJSON($data);
|
| 5206 |
+
}
|
| 5207 |
+
}
|
| 5208 |
+
return $data;
|
| 5209 |
+
}
|
| 5210 |
+
/**
|
| 5211 |
+
* Enter description here...
|
| 5212 |
+
*
|
| 5213 |
+
* @param array|phpQuery $data
|
| 5214 |
+
*
|
| 5215 |
+
*/
|
| 5216 |
+
public static function param($data) {
|
| 5217 |
+
return http_build_query($data, null, '&');
|
| 5218 |
+
}
|
| 5219 |
+
public static function get($url, $data = null, $callback = null, $type = null) {
|
| 5220 |
+
if (!is_array($data)) {
|
| 5221 |
+
$callback = $data;
|
| 5222 |
+
$data = null;
|
| 5223 |
+
}
|
| 5224 |
+
// TODO some array_values on this shit
|
| 5225 |
+
return phpQuery::ajax(array(
|
| 5226 |
+
'type' => 'GET',
|
| 5227 |
+
'url' => $url,
|
| 5228 |
+
'data' => $data,
|
| 5229 |
+
'success' => $callback,
|
| 5230 |
+
'dataType' => $type,
|
| 5231 |
+
));
|
| 5232 |
+
}
|
| 5233 |
+
public static function post($url, $data = null, $callback = null, $type = null) {
|
| 5234 |
+
if (!is_array($data)) {
|
| 5235 |
+
$callback = $data;
|
| 5236 |
+
$data = null;
|
| 5237 |
+
}
|
| 5238 |
+
return phpQuery::ajax(array(
|
| 5239 |
+
'type' => 'POST',
|
| 5240 |
+
'url' => $url,
|
| 5241 |
+
'data' => $data,
|
| 5242 |
+
'success' => $callback,
|
| 5243 |
+
'dataType' => $type,
|
| 5244 |
+
));
|
| 5245 |
+
}
|
| 5246 |
+
public static function getJSON($url, $data = null, $callback = null) {
|
| 5247 |
+
if (!is_array($data)) {
|
| 5248 |
+
$callback = $data;
|
| 5249 |
+
$data = null;
|
| 5250 |
+
}
|
| 5251 |
+
// TODO some array_values on this shit
|
| 5252 |
+
return phpQuery::ajax(array(
|
| 5253 |
+
'type' => 'GET',
|
| 5254 |
+
'url' => $url,
|
| 5255 |
+
'data' => $data,
|
| 5256 |
+
'success' => $callback,
|
| 5257 |
+
'dataType' => 'json',
|
| 5258 |
+
));
|
| 5259 |
+
}
|
| 5260 |
+
public static function ajaxSetup($options) {
|
| 5261 |
+
self::$ajaxSettings = array_merge(
|
| 5262 |
+
self::$ajaxSettings,
|
| 5263 |
+
$options
|
| 5264 |
+
);
|
| 5265 |
+
}
|
| 5266 |
+
public static function ajaxAllowHost($host1, $host2 = null, $host3 = null) {
|
| 5267 |
+
$loop = is_array($host1)
|
| 5268 |
+
? $host1
|
| 5269 |
+
: func_get_args();
|
| 5270 |
+
foreach($loop as $host) {
|
| 5271 |
+
if ($host && ! in_array($host, phpQuery::$ajaxAllowedHosts)) {
|
| 5272 |
+
phpQuery::$ajaxAllowedHosts[] = $host;
|
| 5273 |
+
}
|
| 5274 |
+
}
|
| 5275 |
+
}
|
| 5276 |
+
public static function ajaxAllowURL($url1, $url2 = null, $url3 = null) {
|
| 5277 |
+
$loop = is_array($url1)
|
| 5278 |
+
? $url1
|
| 5279 |
+
: func_get_args();
|
| 5280 |
+
foreach($loop as $url)
|
| 5281 |
+
phpQuery::ajaxAllowHost(parse_url($url, PHP_URL_HOST));
|
| 5282 |
+
}
|
| 5283 |
+
/**
|
| 5284 |
+
* Returns JSON representation of $data.
|
| 5285 |
+
*
|
| 5286 |
+
* @static
|
| 5287 |
+
* @param mixed $data
|
| 5288 |
+
* @return string
|
| 5289 |
+
*/
|
| 5290 |
+
public static function toJSON($data) {
|
| 5291 |
+
if (function_exists('json_encode'))
|
| 5292 |
+
return json_encode($data);
|
| 5293 |
+
require_once('Zend/Json/Encoder.php');
|
| 5294 |
+
return Zend_Json_Encoder::encode($data);
|
| 5295 |
+
}
|
| 5296 |
+
/**
|
| 5297 |
+
* Parses JSON into proper PHP type.
|
| 5298 |
+
*
|
| 5299 |
+
* @static
|
| 5300 |
+
* @param string $json
|
| 5301 |
+
* @return mixed
|
| 5302 |
+
*/
|
| 5303 |
+
public static function parseJSON($json) {
|
| 5304 |
+
if (function_exists('json_decode')) {
|
| 5305 |
+
$return = json_decode(trim($json), true);
|
| 5306 |
+
// json_decode and UTF8 issues
|
| 5307 |
+
if (isset($return))
|
| 5308 |
+
return $return;
|
| 5309 |
+
}
|
| 5310 |
+
require_once('Zend/Json/Decoder.php');
|
| 5311 |
+
return Zend_Json_Decoder::decode($json);
|
| 5312 |
+
}
|
| 5313 |
+
/**
|
| 5314 |
+
* Returns source's document ID.
|
| 5315 |
+
*
|
| 5316 |
+
* @param $source DOMNode|phpQueryObject
|
| 5317 |
+
* @return string
|
| 5318 |
+
*/
|
| 5319 |
+
public static function getDocumentID($source) {
|
| 5320 |
+
if ($source instanceof DOMDOCUMENT) {
|
| 5321 |
+
foreach(phpQuery::$documents as $id => $document) {
|
| 5322 |
+
if ($source->isSameNode($document->document))
|
| 5323 |
+
return $id;
|
| 5324 |
+
}
|
| 5325 |
+
} else if ($source instanceof DOMNODE) {
|
| 5326 |
+
foreach(phpQuery::$documents as $id => $document) {
|
| 5327 |
+
if ($source->ownerDocument->isSameNode($document->document))
|
| 5328 |
+
return $id;
|
| 5329 |
+
}
|
| 5330 |
+
} else if ($source instanceof phpQueryObject)
|
| 5331 |
+
return $source->getDocumentID();
|
| 5332 |
+
else if (is_string($source) && isset(phpQuery::$documents[$source]))
|
| 5333 |
+
return $source;
|
| 5334 |
+
}
|
| 5335 |
+
/**
|
| 5336 |
+
* Get DOMDocument object related to $source.
|
| 5337 |
+
* Returns null if such document doesn't exist.
|
| 5338 |
+
*
|
| 5339 |
+
* @param $source DOMNode|phpQueryObject|string
|
| 5340 |
+
* @return string
|
| 5341 |
+
*/
|
| 5342 |
+
public static function getDOMDocument($source) {
|
| 5343 |
+
if ($source instanceof DOMDOCUMENT)
|
| 5344 |
+
return $source;
|
| 5345 |
+
$source = self::getDocumentID($source);
|
| 5346 |
+
return $source
|
| 5347 |
+
? self::$documents[$id]['document']
|
| 5348 |
+
: null;
|
| 5349 |
+
}
|
| 5350 |
+
|
| 5351 |
+
// UTILITIES
|
| 5352 |
+
// http://docs.jquery.com/Utilities
|
| 5353 |
+
|
| 5354 |
+
/**
|
| 5355 |
+
*
|
| 5356 |
+
* @return unknown_type
|
| 5357 |
+
* @link http://docs.jquery.com/Utilities/jQuery.makeArray
|
| 5358 |
+
*/
|
| 5359 |
+
public static function makeArray($obj) {
|
| 5360 |
+
$array = array();
|
| 5361 |
+
if (is_object($object) && $object instanceof DOMNODELIST) {
|
| 5362 |
+
foreach($object as $value)
|
| 5363 |
+
$array[] = $value;
|
| 5364 |
+
} else if (is_object($object) && ! ($object instanceof Iterator)) {
|
| 5365 |
+
foreach(get_object_vars($object) as $name => $value)
|
| 5366 |
+
$array[0][$name] = $value;
|
| 5367 |
+
} else {
|
| 5368 |
+
foreach($object as $name => $value)
|
| 5369 |
+
$array[0][$name] = $value;
|
| 5370 |
+
}
|
| 5371 |
+
return $array;
|
| 5372 |
+
}
|
| 5373 |
+
public static function inArray($value, $array) {
|
| 5374 |
+
return in_array($value, $array);
|
| 5375 |
+
}
|
| 5376 |
+
/**
|
| 5377 |
+
*
|
| 5378 |
+
* @param $object
|
| 5379 |
+
* @param $callback
|
| 5380 |
+
* @return unknown_type
|
| 5381 |
+
* @link http://docs.jquery.com/Utilities/jQuery.each
|
| 5382 |
+
*/
|
| 5383 |
+
public static function each($object, $callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 5384 |
+
$paramStructure = null;
|
| 5385 |
+
if (func_num_args() > 2) {
|
| 5386 |
+
$paramStructure = func_get_args();
|
| 5387 |
+
$paramStructure = array_slice($paramStructure, 2);
|
| 5388 |
+
}
|
| 5389 |
+
if (is_object($object) && ! ($object instanceof Iterator)) {
|
| 5390 |
+
foreach(get_object_vars($object) as $name => $value)
|
| 5391 |
+
phpQuery::callbackRun($callback, array($name, $value), $paramStructure);
|
| 5392 |
+
} else {
|
| 5393 |
+
foreach($object as $name => $value)
|
| 5394 |
+
phpQuery::callbackRun($callback, array($name, $value), $paramStructure);
|
| 5395 |
+
}
|
| 5396 |
+
}
|
| 5397 |
+
/**
|
| 5398 |
+
*
|
| 5399 |
+
* @link http://docs.jquery.com/Utilities/jQuery.map
|
| 5400 |
+
*/
|
| 5401 |
+
public static function map($array, $callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 5402 |
+
$result = array();
|
| 5403 |
+
$paramStructure = null;
|
| 5404 |
+
if (func_num_args() > 2) {
|
| 5405 |
+
$paramStructure = func_get_args();
|
| 5406 |
+
$paramStructure = array_slice($paramStructure, 2);
|
| 5407 |
+
}
|
| 5408 |
+
foreach($array as $v) {
|
| 5409 |
+
$vv = phpQuery::callbackRun($callback, array($v), $paramStructure);
|
| 5410 |
+
// $callbackArgs = $args;
|
| 5411 |
+
// foreach($args as $i => $arg) {
|
| 5412 |
+
// $callbackArgs[$i] = $arg instanceof CallbackParam
|
| 5413 |
+
// ? $v
|
| 5414 |
+
// : $arg;
|
| 5415 |
+
// }
|
| 5416 |
+
// $vv = call_user_func_array($callback, $callbackArgs);
|
| 5417 |
+
if (is_array($vv)) {
|
| 5418 |
+
foreach($vv as $vvv)
|
| 5419 |
+
$result[] = $vvv;
|
| 5420 |
+
} else if ($vv !== null) {
|
| 5421 |
+
$result[] = $vv;
|
| 5422 |
+
}
|
| 5423 |
+
}
|
| 5424 |
+
return $result;
|
| 5425 |
+
}
|
| 5426 |
+
/**
|
| 5427 |
+
*
|
| 5428 |
+
* @param $callback Callback
|
| 5429 |
+
* @param $params
|
| 5430 |
+
* @param $paramStructure
|
| 5431 |
+
* @return unknown_type
|
| 5432 |
+
*/
|
| 5433 |
+
public static function callbackRun($callback, $params = array(), $paramStructure = null) {
|
| 5434 |
+
if (! $callback)
|
| 5435 |
+
return;
|
| 5436 |
+
if ($callback instanceof CallbackParameterToReference) {
|
| 5437 |
+
// TODO support ParamStructure to select which $param push to reference
|
| 5438 |
+
if (isset($params[0]))
|
| 5439 |
+
$callback->callback = $params[0];
|
| 5440 |
+
return true;
|
| 5441 |
+
}
|
| 5442 |
+
if ($callback instanceof Callback) {
|
| 5443 |
+
$paramStructure = $callback->params;
|
| 5444 |
+
$callback = $callback->callback;
|
| 5445 |
+
}
|
| 5446 |
+
if (! $paramStructure)
|
| 5447 |
+
return call_user_func_array($callback, $params);
|
| 5448 |
+
$p = 0;
|
| 5449 |
+
foreach($paramStructure as $i => $v) {
|
| 5450 |
+
$paramStructure[$i] = $v instanceof CallbackParam
|
| 5451 |
+
? $params[$p++]
|
| 5452 |
+
: $v;
|
| 5453 |
+
}
|
| 5454 |
+
return call_user_func_array($callback, $paramStructure);
|
| 5455 |
+
}
|
| 5456 |
+
/**
|
| 5457 |
+
* Merge 2 phpQuery objects.
|
| 5458 |
+
* @param array $one
|
| 5459 |
+
* @param array $two
|
| 5460 |
+
* @protected
|
| 5461 |
+
* @todo node lists, phpQueryObject
|
| 5462 |
+
*/
|
| 5463 |
+
public static function merge($one, $two) {
|
| 5464 |
+
$elements = $one->elements;
|
| 5465 |
+
foreach($two->elements as $node) {
|
| 5466 |
+
$exists = false;
|
| 5467 |
+
foreach($elements as $node2) {
|
| 5468 |
+
if ($node2->isSameNode($node))
|
| 5469 |
+
$exists = true;
|
| 5470 |
+
}
|
| 5471 |
+
if (! $exists)
|
| 5472 |
+
$elements[] = $node;
|
| 5473 |
+
}
|
| 5474 |
+
return $elements;
|
| 5475 |
+
// $one = $one->newInstance();
|
| 5476 |
+
// $one->elements = $elements;
|
| 5477 |
+
// return $one;
|
| 5478 |
+
}
|
| 5479 |
+
/**
|
| 5480 |
+
*
|
| 5481 |
+
* @param $array
|
| 5482 |
+
* @param $callback
|
| 5483 |
+
* @param $invert
|
| 5484 |
+
* @return unknown_type
|
| 5485 |
+
* @link http://docs.jquery.com/Utilities/jQuery.grep
|
| 5486 |
+
*/
|
| 5487 |
+
public static function grep($array, $callback, $invert = false) {
|
| 5488 |
+
$result = array();
|
| 5489 |
+
foreach($array as $k => $v) {
|
| 5490 |
+
$r = call_user_func_array($callback, array($v, $k));
|
| 5491 |
+
if ($r === !(bool)$invert)
|
| 5492 |
+
$result[] = $v;
|
| 5493 |
+
}
|
| 5494 |
+
return $result;
|
| 5495 |
+
}
|
| 5496 |
+
public static function unique($array) {
|
| 5497 |
+
return array_unique($array);
|
| 5498 |
+
}
|
| 5499 |
+
/**
|
| 5500 |
+
*
|
| 5501 |
+
* @param $function
|
| 5502 |
+
* @return unknown_type
|
| 5503 |
+
* @TODO there are problems with non-static methods, second parameter pass it
|
| 5504 |
+
* but doesnt verify is method is really callable
|
| 5505 |
+
*/
|
| 5506 |
+
public static function isFunction($function) {
|
| 5507 |
+
return is_callable($function);
|
| 5508 |
+
}
|
| 5509 |
+
public static function trim($str) {
|
| 5510 |
+
return trim($str);
|
| 5511 |
+
}
|
| 5512 |
+
/* PLUGINS NAMESPACE */
|
| 5513 |
+
/**
|
| 5514 |
+
*
|
| 5515 |
+
* @param $url
|
| 5516 |
+
* @param $callback
|
| 5517 |
+
* @param $param1
|
| 5518 |
+
* @param $param2
|
| 5519 |
+
* @param $param3
|
| 5520 |
+
* @return phpQueryObject
|
| 5521 |
+
*/
|
| 5522 |
+
public static function browserGet($url, $callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 5523 |
+
if (self::plugin('WebBrowser')) {
|
| 5524 |
+
$params = func_get_args();
|
| 5525 |
+
return self::callbackRun(array(self::$plugins, 'browserGet'), $params);
|
| 5526 |
+
} else {
|
| 5527 |
+
self::debug('WebBrowser plugin not available...');
|
| 5528 |
+
}
|
| 5529 |
+
}
|
| 5530 |
+
/**
|
| 5531 |
+
*
|
| 5532 |
+
* @param $url
|
| 5533 |
+
* @param $data
|
| 5534 |
+
* @param $callback
|
| 5535 |
+
* @param $param1
|
| 5536 |
+
* @param $param2
|
| 5537 |
+
* @param $param3
|
| 5538 |
+
* @return phpQueryObject
|
| 5539 |
+
*/
|
| 5540 |
+
public static function browserPost($url, $data, $callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 5541 |
+
if (self::plugin('WebBrowser')) {
|
| 5542 |
+
$params = func_get_args();
|
| 5543 |
+
return self::callbackRun(array(self::$plugins, 'browserPost'), $params);
|
| 5544 |
+
} else {
|
| 5545 |
+
self::debug('WebBrowser plugin not available...');
|
| 5546 |
+
}
|
| 5547 |
+
}
|
| 5548 |
+
/**
|
| 5549 |
+
*
|
| 5550 |
+
* @param $ajaxSettings
|
| 5551 |
+
* @param $callback
|
| 5552 |
+
* @param $param1
|
| 5553 |
+
* @param $param2
|
| 5554 |
+
* @param $param3
|
| 5555 |
+
* @return phpQueryObject
|
| 5556 |
+
*/
|
| 5557 |
+
public static function browser($ajaxSettings, $callback, $param1 = null, $param2 = null, $param3 = null) {
|
| 5558 |
+
if (self::plugin('WebBrowser')) {
|
| 5559 |
+
$params = func_get_args();
|
| 5560 |
+
return self::callbackRun(array(self::$plugins, 'browser'), $params);
|
| 5561 |
+
} else {
|
| 5562 |
+
self::debug('WebBrowser plugin not available...');
|
| 5563 |
+
}
|
| 5564 |
+
}
|
| 5565 |
+
/**
|
| 5566 |
+
*
|
| 5567 |
+
* @param $code
|
| 5568 |
+
* @return string
|
| 5569 |
+
*/
|
| 5570 |
+
public static function php($code) {
|
| 5571 |
+
return self::code('php', $code);
|
| 5572 |
+
}
|
| 5573 |
+
/**
|
| 5574 |
+
*
|
| 5575 |
+
* @param $type
|
| 5576 |
+
* @param $code
|
| 5577 |
+
* @return string
|
| 5578 |
+
*/
|
| 5579 |
+
public static function code($type, $code) {
|
| 5580 |
+
return "<$type><!-- ".trim($code)." --></$type>";
|
| 5581 |
+
}
|
| 5582 |
+
|
| 5583 |
+
public static function __callStatic($method, $params) {
|
| 5584 |
+
return call_user_func_array(
|
| 5585 |
+
array(phpQuery::$plugins, $method),
|
| 5586 |
+
$params
|
| 5587 |
+
);
|
| 5588 |
+
}
|
| 5589 |
+
protected static function dataSetupNode($node, $documentID) {
|
| 5590 |
+
// search are return if alredy exists
|
| 5591 |
+
foreach(phpQuery::$documents[$documentID]->dataNodes as $dataNode) {
|
| 5592 |
+
if ($node->isSameNode($dataNode))
|
| 5593 |
+
return $dataNode;
|
| 5594 |
+
}
|
| 5595 |
+
// if doesn't, add it
|
| 5596 |
+
phpQuery::$documents[$documentID]->dataNodes[] = $node;
|
| 5597 |
+
return $node;
|
| 5598 |
+
}
|
| 5599 |
+
protected static function dataRemoveNode($node, $documentID) {
|
| 5600 |
+
// search are return if alredy exists
|
| 5601 |
+
foreach(phpQuery::$documents[$documentID]->dataNodes as $k => $dataNode) {
|
| 5602 |
+
if ($node->isSameNode($dataNode)) {
|
| 5603 |
+
unset(self::$documents[$documentID]->dataNodes[$k]);
|
| 5604 |
+
unset(self::$documents[$documentID]->data[ $dataNode->dataID ]);
|
| 5605 |
+
}
|
| 5606 |
+
}
|
| 5607 |
+
}
|
| 5608 |
+
public static function data($node, $name, $data, $documentID = null) {
|
| 5609 |
+
if (! $documentID)
|
| 5610 |
+
// TODO check if this works
|
| 5611 |
+
$documentID = self::getDocumentID($node);
|
| 5612 |
+
$document = phpQuery::$documents[$documentID];
|
| 5613 |
+
$node = self::dataSetupNode($node, $documentID);
|
| 5614 |
+
if (! isset($node->dataID))
|
| 5615 |
+
$node->dataID = ++phpQuery::$documents[$documentID]->uuid;
|
| 5616 |
+
$id = $node->dataID;
|
| 5617 |
+
if (! isset($document->data[$id]))
|
| 5618 |
+
$document->data[$id] = array();
|
| 5619 |
+
if (! is_null($data))
|
| 5620 |
+
$document->data[$id][$name] = $data;
|
| 5621 |
+
if ($name) {
|
| 5622 |
+
if (isset($document->data[$id][$name]))
|
| 5623 |
+
return $document->data[$id][$name];
|
| 5624 |
+
} else
|
| 5625 |
+
return $id;
|
| 5626 |
+
}
|
| 5627 |
+
public static function removeData($node, $name, $documentID) {
|
| 5628 |
+
if (! $documentID)
|
| 5629 |
+
// TODO check if this works
|
| 5630 |
+
$documentID = self::getDocumentID($node);
|
| 5631 |
+
$document = phpQuery::$documents[$documentID];
|
| 5632 |
+
$node = self::dataSetupNode($node, $documentID);
|
| 5633 |
+
$id = $node->dataID;
|
| 5634 |
+
if ($name) {
|
| 5635 |
+
if (isset($document->data[$id][$name]))
|
| 5636 |
+
unset($document->data[$id][$name]);
|
| 5637 |
+
$name = null;
|
| 5638 |
+
foreach($document->data[$id] as $name)
|
| 5639 |
+
break;
|
| 5640 |
+
if (! $name)
|
| 5641 |
+
self::removeData($node, $name, $documentID);
|
| 5642 |
+
} else {
|
| 5643 |
+
self::dataRemoveNode($node, $documentID);
|
| 5644 |
+
}
|
| 5645 |
+
}
|
| 5646 |
+
}
|
| 5647 |
+
/**
|
| 5648 |
+
* Plugins static namespace class.
|
| 5649 |
+
*
|
| 5650 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 5651 |
+
* @package phpQuery
|
| 5652 |
+
* @todo move plugin methods here (as statics)
|
| 5653 |
+
*/
|
| 5654 |
+
class phpQueryPlugins {
|
| 5655 |
+
public function __call($method, $args) {
|
| 5656 |
+
if (isset(phpQuery::$extendStaticMethods[$method])) {
|
| 5657 |
+
$return = call_user_func_array(
|
| 5658 |
+
phpQuery::$extendStaticMethods[$method],
|
| 5659 |
+
$args
|
| 5660 |
+
);
|
| 5661 |
+
} else if (isset(phpQuery::$pluginsStaticMethods[$method])) {
|
| 5662 |
+
$class = phpQuery::$pluginsStaticMethods[$method];
|
| 5663 |
+
$realClass = "phpQueryPlugin_$class";
|
| 5664 |
+
$return = call_user_func_array(
|
| 5665 |
+
array($realClass, $method),
|
| 5666 |
+
$args
|
| 5667 |
+
);
|
| 5668 |
+
return isset($return)
|
| 5669 |
+
? $return
|
| 5670 |
+
: $this;
|
| 5671 |
+
} else
|
| 5672 |
+
throw new Exception("Method '{$method}' doesnt exist");
|
| 5673 |
+
}
|
| 5674 |
+
}
|
| 5675 |
+
/**
|
| 5676 |
+
* Shortcut to phpQuery::pq($arg1, $context)
|
| 5677 |
+
* Chainable.
|
| 5678 |
+
*
|
| 5679 |
+
* @see phpQuery::pq()
|
| 5680 |
+
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
|
| 5681 |
+
* @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
|
| 5682 |
+
* @package phpQuery
|
| 5683 |
+
*/
|
| 5684 |
+
function pq($arg1, $context = null) {
|
| 5685 |
+
$args = func_get_args();
|
| 5686 |
+
return call_user_func_array(
|
| 5687 |
+
array('phpQuery', 'pq'),
|
| 5688 |
+
$args
|
| 5689 |
+
);
|
| 5690 |
+
}
|
| 5691 |
+
// add plugins dir and Zend framework to include path
|
| 5692 |
+
set_include_path(
|
| 5693 |
+
get_include_path()
|
| 5694 |
+
.PATH_SEPARATOR.dirname(__FILE__).'/phpQuery/'
|
| 5695 |
+
.PATH_SEPARATOR.dirname(__FILE__).'/phpQuery/plugins/'
|
| 5696 |
+
);
|
| 5697 |
+
// why ? no __call nor __get for statics in php...
|
| 5698 |
+
// XXX __callStatic will be available in PHP 5.3
|
| 5699 |
+
phpQuery::$plugins = new phpQueryPlugins();
|
| 5700 |
+
// include bootstrap file (personal library config)
|
| 5701 |
+
if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php'))
|
| 5702 |
+
require_once dirname(__FILE__).'/phpQuery/bootstrap.php';
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>MoipExpress</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.gnu.org/copyleft/gpl.html">GPL v3</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>A melhor e mais nova integração para a solução de pagamentos MoIP.</summary>
|
| 10 |
+
<description>A melhor e mais nova integração para a solução de pagamentos MoIP.</description>
|
| 11 |
+
<notes>Sinta-se a vontade para contatar o suporte</notes>
|
| 12 |
+
<authors><author><name>Raul Sakai</name><user>rqsakai</user><email>rqsakai@gmail.com</email></author></authors>
|
| 13 |
+
<date>2014-07-02</date>
|
| 14 |
+
<time>21:02:43</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Monstroestudio"><dir name="Moip"><dir name="Block"><file name="Form.php" hash="f2bcb847f4c3421180136add3333fc52"/><file name="Redirect.php" hash="867de41249dabc53ec0834f2cc1311bf"/></dir><dir name="Helper"><file name="Data.php" hash="cc959503224982e903b54c0cd2f4af75"/></dir><dir name="Model"><file name="Abstract.php" hash="057d418e2eb63f65dbe4b72290ce2ac4"/><file name="Observer.php" hash="0a51515622da6dac68a745d413ebe126"/><file name="PaymentMethod.php" hash="3cdbc0544cf1efaf30e862d159270644"/><dir name="Resource"><dir name="Safe"><dir name="Collection"><file name="Abstract.php" hash="1226a0f68556e70a06ded8c36122f775"/></dir><file name="Collection.php" hash="db5d0d3d5360569db7d37b015cdbdee6"/></dir><file name="Safe.php" hash="fff8bc262d55296cac2886b39f043b2d"/><dir name="Transactions"><dir name="Collection"><file name="Abstract.php" hash="579220db5fc7f5f0cede6e978c58eada"/></dir><file name="Collection.php" hash="0efc676bb425f3b60484500a6dab52fd"/></dir><file name="Transactions.php" hash="25b1ba30771a1f32727442f4dfeabcfb"/></dir><file name="Safe.php" hash="e66911ae2b4e875fbedc7c063162adb5"/><dir name="Source"><file name="Ccmaxparcelas.php" hash="6f787154ed5c3e4f3bbcdc4db539c39c"/><file name="Paymentmethods.php" hash="cdbcf39fdf3bc3ceeab4d8e6e80317b6"/><file name="Recebimento.php" hash="b65926935d31cbd3709aee596e5c31c6"/><file name="Tipovencboleto.php" hash="fcb4363c7d842b5c02260d9999c52d66"/></dir><file name="Transactions.php" hash="eddb3201f6ac97ea4ec720e0e4f755a5"/></dir><dir name="controllers"><file name="CheckoutController.php" hash="7edd9f00b87a1d1e4583cee87918631e"/></dir><dir name="etc"><file name="config.xml" hash="e6e0359eb2b181dbaa1ca4d57cdda233"/><file name="system.xml" hash="2a77a802c3362a5f1af89f843fd0f0ed"/></dir><dir name="sql"><dir name="moip_setup"><file name="mysql4-install-1.0.0.php" hash="a835f6d87b9c0a50edc35d84e0858eb7"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="monstroestudio"><dir name="moip"><file name="form.phtml" hash="6e3585a0b1362890a6a4bc4f8ac597bc"/><file name="redirect.phtml" hash="3f87c1b3105ba38630b17abddba10227"/></dir></dir></dir><dir name="layout"><dir name="monstroestudio"><file name="moip.xml" hash="6d9c361931c42324171522ca732d76ea"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="monstroestudio"><dir name="moip"><dir name="css"><file name="styles.css" hash="fc1ef0a19b7c8ac43517924749c837b0"/></dir><dir name="images"><file name="amex.png" hash="ddae1391e6cc2b9ed02755e1bda42127"/><file name="banrisul.png" hash="4a3feb3468e0b5fb72f096c2762d8806"/><file name="bb.png" hash="066e08f866baf93b77694bf354eec913"/><file name="boleto.png" hash="5670bee3689eef1c39e0d35108205b8d"/><file name="bradesco-boleto.jpg" hash="0a9c5b2544e5a07b76be5f714729a11f"/><file name="bradesco.png" hash="8d8919bf93cc04a512f86e3d20003c01"/><file name="cc.png" hash="9355033ab955d67a5b87feb5a72a3786"/><file name="diners.png" hash="c0624bfa6bde58d5d6defb4849148d23"/><file name="hiper.png" hash="2785865b79748180647bdc3b470101c0"/><file name="itau.png" hash="9b4206fb76f64a86437c80450ba363be"/><file name="master.png" hash="3794747a6bcefcd3975966501ff44782"/><file name="moip-warning.png" hash="7f532dbf2fc16f6378cdefbe92e458db"/><file name="printer.png" hash="1ab5e87a5eff796f63d8134b48a6d02a"/><file name="transf.png" hash="14eafc26fdca09d2bb8c76702d785867"/><file name="transferencia-icon.png" hash="b11dd5f71eb7c1e04fdf8a4b4112c066"/><file name="visa.png" hash="c0044c9a4d4ebcc2773bd9c13620ffce"/></dir><dir name="js"><file name="creditcard.min.js" hash="364e168e2ebd3269691dcdcdbb0fea5e"/><file name="jquery.js" hash="242361900ae3ebb31f8b9a62a9d549f6"/><file name="moip-form.js" hash="870c038a5c783f75ccf0bdeba5e3c731"/><file name="prototype.maskedinput.js" hash="23acf0dcd74dc380cf1d9059ff74111b"/><file name="validations.js" hash="1105a40f058db378ad1b059505a35d1f"/></dir></dir></dir></dir></dir></dir></target><target name="magelib"><dir name="Moip"><file name="Moip.php" hash="9a5033f185a7179b4ffbf46911b46acc"/><file name="MoipClient.php" hash="ad0b0c4b005bd36fe7499df75483b1bb"/><file name="MoipEnvironment.php" hash="0f69d07dd42baa5ea70af1df10a03003"/><file name="MoipResponse.php" hash="3fc4b67f28adf2c27b968756e0cdfca5"/><file name="MoipStatus.php" hash="9f61696ffb0819ac9cef7a89736edc9b"/><dir name="phpQuery"><file name="phpQuery.php" hash="5cb41d4d677a5f076c2a1fc26430dfe6"/></dir></dir></target><target name="mageetc"><dir name="."><file name="Monstroestudio_Moip.xml" hash=""/></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>4.0.0.</min><max>7.0.0</max></php><package><name>Mage_Core_Payment</name><channel>connect.magentocommerce.com/core</channel><min/><max/></package></required></dependencies>
|
| 18 |
+
</package>
|
skin/frontend/default/default/monstroestudio/moip/css/styles.css
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.moip-paygate{display:block;clear:both;width:100%;margin-bottom:20px;float: left;min-width:500px;}
|
| 2 |
+
.moip-paygate > div{display:block;float:left;clear:none;margin:0;padding:0;}
|
| 3 |
+
.moip-paygate > div.col-left{width:30%;min-width:185px;}
|
| 4 |
+
.moip-paygate > div.col-left > span{display:block;cursor:pointer;float:left;width:100%;;cleaR:both;background:#fff;color:#333;padding: 10px 0;border:1px solid #f0f0f0;border-radius: 5px 0 0 5px;-webkit-border-radius: 5px 0 0 5px;-moz-border-radius: 5px 0 0 5px;-o-border-radius: 5px 0 0 5px;-ms-border-radius: 5px 0 0 5px;transition: all 0.3s ease;-webkit-transition: all 0.3s ease;-o-transition: all 0.3s ease;-moz-transition: all 0.3s ease;-ms-transition: all 0.3s ease;line-height:28px;}
|
| 5 |
+
.moip-paygate > div.col-left > span:hover{background:#f9f9f9;}
|
| 6 |
+
.moip-paygate > div.col-left > span.active{background:#f0f0f0;margin-left:-10px;padding-right:10px;}
|
| 7 |
+
.moip-paygate > div.col-left > span > span{float:left; margin-left:15px;}
|
| 8 |
+
.moip-paygate > div.col-left > span > img{float:right;height:100%;width: auto;max-height: 28px;margin-right: 10px;margin-top: 3%;}
|
| 9 |
+
|
| 10 |
+
.moip-paygate > div.col-right{width:70%;min-width:325px;background:#f0f0f0;padding:15px 0;border-radius:0 5px 5px 5px;-webkit-border-radius:0 5px 5px 5px;-moz-border-radius:0 5px 5px 5px;-ms-border-radius:0 5px 5px 5px;-o-border-radius:0 5px 5px 5px;}
|
| 11 |
+
.moip-paygate > div.col-right .moip-payment-method{padding:0 10px;margin:0;overflow:hidden;}
|
| 12 |
+
.moip-paygate > div.col-right .moip-payment-method.active{display:block;}
|
| 13 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li{transition: all 0.3s ease;-webkit-transition: all 0.3s ease;-o-transition: all 0.3s ease;-moz-transition: all 0.3s ease;-ms-transition: all 0.3s ease;height:auto;position:relative;}
|
| 14 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.hide{}
|
| 15 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.bandeira > label{display:block;float:left;margin-right:5px;text-align:center;cursor:pointer;width: 23%;}
|
| 16 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.bandeira > label img{clear:both;display:block;margin-top:2px;transition: all 0.3s ease;-webkit-transition: all 0.3s ease;-o-transition: all 0.3s ease;-moz-transition: all 0.3s ease;-ms-transition: all 0.3s ease;width:100%;height:auto;-webkit-filter: grayscale(0.8);-moz-filter: grayscale(0.8);-o-filter: grayscale(0.8);filter: grayscale(0.8);}
|
| 17 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.bandeira > label img.active{opacity:1;-webkit-filter: grayscale(0);-moz-filter: grayscale(0);-o-filter: grayscale(0);filter: grayscale(0);}
|
| 18 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.bandeira > label div{width:400%;text-align:left;}
|
| 19 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="cc"] ul.form-list > li.bandeira > label{width:10%;max-width:45px;}
|
| 20 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="cc"] ul.form-list > li.bandeira > label div{width:500%;}
|
| 21 |
+
|
| 22 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li .moip-tooltip{position:absolute;display:block;background: #000;color:#fff;border-radius: 50px; padding: 2px 8px;display:block;left:170px;cursor:pointer;margin-top: 2.5%;}
|
| 23 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li .moip-tooltip .tip{position:absolute;display:none;top: -100%;width:200px;background:#fff;color:#000;padding: 10px;border-radius:10px;box-shadow:0px 0px 5px #666;margin-top:-30px;left:-7px;}
|
| 24 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li .moip-tooltip .tip:after{content:" ";border-top: 8px solid #fff;border-right: 8px solid transparent;border-left: 8px solid transparent;position:absolute;top:100%;left:5%;}
|
| 25 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li .moip-tooltip:hover .tip{display:block;}
|
| 26 |
+
|
| 27 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide .input-text, .moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide select{width:262px;padding: 5px 0;text-indent:10px;}
|
| 28 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide select{display:block;}
|
| 29 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.cc .input-text{padding: 13px 0;}
|
| 30 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.validade label{cleaR:none; float:lefT;width:auto;padding-top:5px;}
|
| 31 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.validade .input-box{cleaR:none;float:lefT;width:auto;margin-left:15px;}
|
| 32 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.validade .input-box .input-text{width:50px;}
|
| 33 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.cvc{position:relative;}
|
| 34 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.cvc label{cleaR:none; float:lefT;width:57px;padding-top:5px;}
|
| 35 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.cvc .input-box{cleaR:none;float:lefT;width:auto;margin-left:15px;}
|
| 36 |
+
.moip-paygate > div.col-right .moip-payment-method ul.form-list > li.wide.cvc .input-box .input-text{width:80px;padding: 13px 0;}
|
| 37 |
+
|
| 38 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="boleto"] > div{min-height:138px;}
|
| 39 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="boleto"] > div > img{float: right;margin-right: 1%;width:20%}
|
| 40 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="boleto"] > div > div{float:left;width: 75%;}
|
| 41 |
+
.moip-paygate > div.col-right .moip-payment-method[data-name="boleto"] > div > div p.desconto{font-size:11pt}
|
| 42 |
+
|
| 43 |
+
.moip-paygate > div.col-right .moip-payment-method p.desconto{font-size:11pt}
|
| 44 |
+
|
| 45 |
+
/* redirect */
|
| 46 |
+
.moip-checkout-authorize .row{clear:both;width:100%;padding:0;margin:0 0 1em 0;float: left;}
|
| 47 |
+
.moip-checkout-authorize .row .col50{float:left;display:block;width:50%;margin:0;padding:0;}
|
| 48 |
+
.moip-checkout-authorize .payment-method-img{float:left;margin:3px 10px 0 0;}
|
| 49 |
+
.moip-checkout-authorize .moip-payment-button{display:block;text-transform: uppercase;font-size: 1.1em;background:#1a4c7c;padding: 0.5em 1em;border-radius: 4px; border:0;border-bottom: 3px solid #000;color: #fff;float: left;line-height: 1;cursor: pointer;text-decoration: none !important;}
|
| 50 |
+
.moip-checkout-authorize .moip-alert{color:#f00;width:100%;max-width:250px;font-size:0.9em;padding-left:25px;background:url(../images/moip-warning.png) no-repeat left center;margin: 1em 0;}
|
| 51 |
+
|
| 52 |
+
.moip-checkout-authorize .dialog{background:#fff;bordeR: 1px solid #999; border-radius: 6px;overflow: hidden;box-shadow: 0 0 10px rgba(0,0,0,0.5);}
|
| 53 |
+
.moip-checkout-authorize .dialog .moip-modal_close{background:none;margin:0;padding:0;left: 100%;float: right;cursor: pointer;}
|
| 54 |
+
.moip-checkout-authorize .dialog .moip-modal_close:after{content:"x"; font-size: 20px;font-weight: bold;line-height: 28px;color: #000000;text-shadow: 0 1px 0 #ffffff;opacity: 0.2;font-weight: bold;margin-left: -1.3em;margin-top: 0.3em;float:lefT;}
|
| 55 |
+
.moip-checkout-authorize .dialog .top.table_window{border-bottom: 1px solid #ccc;}
|
| 56 |
+
.moip-checkout-authorize .dialog .top.table_window,
|
| 57 |
+
.moip-checkout-authorize .dialog .top.table_window tr td{border:0;background:0;}
|
| 58 |
+
.moip-checkout-authorize .dialog .moip-modal_title{text-align:center;font-size:1.4em;color:#444;font-weight:lighter;height: auto;padding: 0.5em 0;border-bottom:1px solid #ccc;color: #666;}
|
| 59 |
+
.moip-checkout-authorize .dialog .bot.table_window{display:none;}
|
| 60 |
+
.moip-checkout-authorize .dialog table.table_window td ,.moip-checkout-authorize .dialog table.table_window th { padding: 0; background: #fff;border: 0;}
|
| 61 |
+
.moip-checkout-authorize .dialog .mid .moip-modal_w,
|
| 62 |
+
.moip-checkout-authorize .dialog .mid .moip-modal_e{padding: 1em;}
|
| 63 |
+
|
| 64 |
+
.moip-checkout-authorize .order-items .buttons-set{display:none;}
|
skin/frontend/default/default/monstroestudio/moip/images/amex.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/banrisul.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/bb.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/boleto.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/bradesco-boleto.jpg
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/bradesco.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/cc.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/diners.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/hiper.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/itau.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/master.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/moip-warning.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/printer.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/transf.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/transferencia-icon.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/images/visa.png
ADDED
|
Binary file
|
skin/frontend/default/default/monstroestudio/moip/js/creditcard.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
var CreditCard={CARDS:{visa:/^4[0-9]{12}(?:[0-9]{3})?$/,master:/^5[1-5][0-9]{14}$/,diners:/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,amex:/^3[47][0-9]{13}$/,discover:/^6(?:011|5[0-9]{2})[0-9]{12}$/,hiper:/^(38|60)(\d{17}|\d{14}|\d{11})$/},TEST_NUMBERS:$w("378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222"),validate:function(a){if(CreditCard.type(a)=='hiper'){return CreditCard.CARDS.hiper.test(CreditCard.strip(a));}else{return CreditCard.verifyLuhn10(a)&&!!CreditCard.type(a)&&!CreditCard.isTestNumber(a)}},verifyLuhn10:function(a){return($A(CreditCard.strip(a)).reverse().inject(0,function(b,d,c){return b+$A((parseInt(d)*[1,2][c%2]).toString()).inject(0,function(e,f){return e+parseInt(f)})})%10==0)},isTestNumber:function(a){return CreditCard.TEST_NUMBERS.include(CreditCard.strip(a))},strip:function(a){return a.gsub(/\s/,"")},type:function(b){for(var a in CreditCard.CARDS){if(CreditCard["is"+a](b)){return a}}}};(function(){for(var a in CreditCard.CARDS){CreditCard["is"+a]=function(b,c){return CreditCard.CARDS[b].test(CreditCard.strip(c))}.curry(a)}})();
|
skin/frontend/default/default/monstroestudio/moip/js/jquery.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
|
| 2 |
+
!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b=a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="<div class='a'></div><div class='a i'></div>",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="<select msallowclip=''><option selected=''></option></select>",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=lb(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=mb(b);function pb(){}pb.prototype=d.filters=d.pseudos,d.setFilters=new pb,g=fb.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){(!c||(e=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?fb.error(a):z(a,i).slice(0)};function qb(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h;
|
| 3 |
+
if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?m.queue(this[0],a):void 0===b?this:this.each(function(){var c=m.queue(this,a,b);m._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&m.dequeue(this,a)})},dequeue:function(a){return this.each(function(){m.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=m.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=m._data(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var S=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=["Top","Right","Bottom","Left"],U=function(a,b){return a=b||a,"none"===m.css(a,"display")||!m.contains(a.ownerDocument,a)},V=m.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===m.type(c)){e=!0;for(h in c)m.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,m.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(m(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav></:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="<input type='radio' checked='checked' name='t'/>",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function ab(){return!0}function bb(){return!1}function cb(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},fix:function(a){if(a[m.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=Z.test(e)?this.mouseHooks:Y.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new m.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=f.srcElement||y),3===a.target.nodeType&&(a.target=a.target.parentNode),a.metaKey=!!a.metaKey,g.filter?g.filter(a,f):a},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button,g=b.fromElement;return null==a.pageX&&null!=b.clientX&&(d=a.target.ownerDocument||y,e=d.documentElement,c=d.body,a.pageX=b.clientX+(e&&e.scrollLeft||c&&c.scrollLeft||0)-(e&&e.clientLeft||c&&c.clientLeft||0),a.pageY=b.clientY+(e&&e.scrollTop||c&&c.scrollTop||0)-(e&&e.clientTop||c&&c.clientTop||0)),!a.relatedTarget&&g&&(a.relatedTarget=g===a.target?b.toElement:g),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==cb()&&this.focus)try{return this.focus(),!1}catch(a){}},delegateType:"focusin"},blur:{trigger:function(){return this===cb()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return m.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):void 0},_default:function(a){return m.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=m.extend(new m.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?m.event.trigger(e,null,b):m.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},m.removeEvent=y.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){var d="on"+b;a.detachEvent&&(typeof a[d]===K&&(a[d]=null),a.detachEvent(d,c))},m.Event=function(a,b){return this instanceof m.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?ab:bb):this.type=a,b&&m.extend(this,b),this.timeStamp=a&&a.timeStamp||m.now(),void(this[m.expando]=!0)):new m.Event(a,b)},m.Event.prototype={isDefaultPrevented:bb,isPropagationStopped:bb,isImmediatePropagationStopped:bb,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=ab,a&&(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=ab,a&&(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=ab,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},m.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){m.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!m.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.submitBubbles||(m.event.special.submit={setup:function(){return m.nodeName(this,"form")?!1:void m.event.add(this,"click._submit keypress._submit",function(a){var b=a.target,c=m.nodeName(b,"input")||m.nodeName(b,"button")?b.form:void 0;c&&!m._data(c,"submitBubbles")&&(m.event.add(c,"submit._submit",function(a){a._submit_bubble=!0}),m._data(c,"submitBubbles",!0))})},postDispatch:function(a){a._submit_bubble&&(delete a._submit_bubble,this.parentNode&&!a.isTrigger&&m.event.simulate("submit",this.parentNode,a,!0))},teardown:function(){return m.nodeName(this,"form")?!1:void m.event.remove(this,"._submit")}}),k.changeBubbles||(m.event.special.change={setup:function(){return X.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(m.event.add(this,"propertychange._change",function(a){"checked"===a.originalEvent.propertyName&&(this._just_changed=!0)}),m.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1),m.event.simulate("change",this,a,!0)})),!1):void m.event.add(this,"beforeactivate._change",function(a){var b=a.target;X.test(b.nodeName)&&!m._data(b,"changeBubbles")&&(m.event.add(b,"change._change",function(a){!this.parentNode||a.isSimulated||a.isTrigger||m.event.simulate("change",this.parentNode,a,!0)}),m._data(b,"changeBubbles",!0))})},handle:function(a){var b=a.target;return this!==b||a.isSimulated||a.isTrigger||"radio"!==b.type&&"checkbox"!==b.type?a.handleObj.handler.apply(this,arguments):void 0},teardown:function(){return m.event.remove(this,"._change"),!X.test(this.nodeName)}}),k.focusinBubbles||m.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){m.event.simulate(b,a.target,m.event.fix(a),!0)};m.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=m._data(d,b);e||d.addEventListener(a,c,!0),m._data(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=m._data(d,b)-1;e?m._data(d,b,e):(d.removeEventListener(a,c,!0),m._removeData(d,b))}}}),m.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(f in a)this.on(f,b,c,a[f],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=bb;else if(!d)return this;return 1===e&&(g=d,d=function(a){return m().off(a),g.apply(this,arguments)},d.guid=g.guid||(g.guid=m.guid++)),this.each(function(){m.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,m(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return(b===!1||"function"==typeof b)&&(c=b,b=void 0),c===!1&&(c=bb),this.each(function(){m.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){m.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?m.event.trigger(a,b,c,!0):void 0}});function db(a){var b=eb.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}var eb="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",fb=/ jQuery\d+="(?:null|\d+)"/g,gb=new RegExp("<(?:"+eb+")[\\s/>]","i"),hb=/^\s+/,ib=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,jb=/<([\w:]+)/,kb=/<tbody/i,lb=/<|&#?\w+;/,mb=/<(?:script|style|link)/i,nb=/checked\s*(?:[^=]|=\s*.checked.)/i,ob=/^$|\/(?:java|ecma)script/i,pb=/^true\/(.*)/,qb=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,rb={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:k.htmlSerialize?[0,"",""]:[1,"X<div>","</div>"]},sb=db(y),tb=sb.appendChild(y.createElement("div"));rb.optgroup=rb.option,rb.tbody=rb.tfoot=rb.colgroup=rb.caption=rb.thead,rb.th=rb.td;function ub(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ub(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function vb(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wb(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xb(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function yb(a){var b=pb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function zb(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Ab(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Bb(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xb(b).text=a.text,yb(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!gb.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(tb.innerHTML=a.outerHTML,tb.removeChild(f=tb.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ub(f),h=ub(a),g=0;null!=(e=h[g]);++g)d[g]&&Bb(e,d[g]);if(b)if(c)for(h=h||ub(a),d=d||ub(f),g=0;null!=(e=h[g]);g++)Ab(e,d[g]);else Ab(a,f);return d=ub(f,"script"),d.length>0&&zb(d,!i&&ub(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=db(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(lb.test(f)){h=h||o.appendChild(b.createElement("div")),i=(jb.exec(f)||["",""])[1].toLowerCase(),l=rb[i]||rb._default,h.innerHTML=l[1]+f.replace(ib,"<$1></$2>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&hb.test(f)&&p.push(b.createTextNode(hb.exec(f)[0])),!k.tbody){f="table"!==i||kb.test(f)?"<table>"!==l[1]||kb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ub(p,"input"),vb),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ub(o.appendChild(f),"script"),g&&zb(h),c)){e=0;while(f=h[e++])ob.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ub(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&zb(ub(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ub(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fb,""):void 0;if(!("string"!=typeof a||mb.test(a)||!k.htmlSerialize&&gb.test(a)||!k.leadingWhitespace&&hb.test(a)||rb[(jb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ib,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ub(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ub(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&nb.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ub(i,"script"),xb),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ub(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,yb),j=0;f>j;j++)d=g[j],ob.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qb,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Cb,Db={};function Eb(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fb(a){var b=y,c=Db[a];return c||(c=Eb(a,b),"none"!==c&&c||(Cb=(Cb||m("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=(Cb[0].contentWindow||Cb[0].contentDocument).document,b.write(),b.close(),c=Eb(a,b),Cb.detach()),Db[a]=c),c}!function(){var a;k.shrinkWrapBlocks=function(){if(null!=a)return a;a=!1;var b,c,d;return c=y.getElementsByTagName("body")[0],c&&c.style?(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:1px;width:1px;zoom:1",b.appendChild(y.createElement("div")).style.width="5px",a=3!==b.offsetWidth),c.removeChild(d),a):void 0}}();var Gb=/^margin/,Hb=new RegExp("^("+S+")(?!px)[a-z%]+$","i"),Ib,Jb,Kb=/^(top|right|bottom|left)$/;a.getComputedStyle?(Ib=function(a){return a.ownerDocument.defaultView.getComputedStyle(a,null)},Jb=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Ib(a),g=c?c.getPropertyValue(b)||c[b]:void 0,c&&(""!==g||m.contains(a.ownerDocument,a)||(g=m.style(a,b)),Hb.test(g)&&Gb.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0===g?g:g+""}):y.documentElement.currentStyle&&(Ib=function(a){return a.currentStyle},Jb=function(a,b,c){var d,e,f,g,h=a.style;return c=c||Ib(a),g=c?c[b]:void 0,null==g&&h&&h[b]&&(g=h[b]),Hb.test(g)&&!Kb.test(b)&&(d=h.left,e=a.runtimeStyle,f=e&&e.left,f&&(e.left=a.currentStyle.left),h.left="fontSize"===b?"1em":g,g=h.pixelLeft+"px",h.left=d,f&&(e.left=f)),void 0===g?g:g+""||"auto"});function Lb(a,b){return{get:function(){var c=a();if(null!=c)return c?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d,e,f,g,h;if(b=y.createElement("div"),b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",d=b.getElementsByTagName("a")[0],c=d&&d.style){c.cssText="float:left;opacity:.5",k.opacity="0.5"===c.opacity,k.cssFloat=!!c.cssFloat,b.style.backgroundClip="content-box",b.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===b.style.backgroundClip,k.boxSizing=""===c.boxSizing||""===c.MozBoxSizing||""===c.WebkitBoxSizing,m.extend(k,{reliableHiddenOffsets:function(){return null==g&&i(),g},boxSizingReliable:function(){return null==f&&i(),f},pixelPosition:function(){return null==e&&i(),e},reliableMarginRight:function(){return null==h&&i(),h}});function i(){var b,c,d,i;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),b.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",e=f=!1,h=!0,a.getComputedStyle&&(e="1%"!==(a.getComputedStyle(b,null)||{}).top,f="4px"===(a.getComputedStyle(b,null)||{width:"4px"}).width,i=b.appendChild(y.createElement("div")),i.style.cssText=b.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",i.style.marginRight=i.style.width="0",b.style.width="1px",h=!parseFloat((a.getComputedStyle(i,null)||{}).marginRight)),b.innerHTML="<table><tr><td></td><td>t</td></tr></table>",i=b.getElementsByTagName("td"),i[0].style.cssText="margin:0;border:0;padding:0;display:none",g=0===i[0].offsetHeight,g&&(i[0].style.display="",i[1].style.display="none",g=0===i[0].offsetHeight),c.removeChild(d))}}}(),m.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var Mb=/alpha\([^)]*\)/i,Nb=/opacity\s*=\s*([^)]*)/,Ob=/^(none|table(?!-c[ea]).+)/,Pb=new RegExp("^("+S+")(.*)$","i"),Qb=new RegExp("^([+-])=("+S+")","i"),Rb={position:"absolute",visibility:"hidden",display:"block"},Sb={letterSpacing:"0",fontWeight:"400"},Tb=["Webkit","O","Moz","ms"];function Ub(a,b){if(b in a)return b;var c=b.charAt(0).toUpperCase()+b.slice(1),d=b,e=Tb.length;while(e--)if(b=Tb[e]+c,b in a)return b;return d}function Vb(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=m._data(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&U(d)&&(f[g]=m._data(d,"olddisplay",Fb(d.nodeName)))):(e=U(d),(c&&"none"!==c||!e)&&m._data(d,"olddisplay",e?c:m.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}function Wb(a,b,c){var d=Pb.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Xb(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=m.css(a,c+T[f],!0,e)),d?("content"===c&&(g-=m.css(a,"padding"+T[f],!0,e)),"margin"!==c&&(g-=m.css(a,"border"+T[f]+"Width",!0,e))):(g+=m.css(a,"padding"+T[f],!0,e),"padding"!==c&&(g+=m.css(a,"border"+T[f]+"Width",!0,e)));return g}function Yb(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=Ib(a),g=k.boxSizing&&"border-box"===m.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=Jb(a,b,f),(0>e||null==e)&&(e=a.style[b]),Hb.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Xb(a,b,c||(g?"border":"content"),d,f)+"px"}m.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=Jb(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":k.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=m.camelCase(b),i=a.style;if(b=m.cssProps[h]||(m.cssProps[h]=Ub(i,h)),g=m.cssHooks[b]||m.cssHooks[h],void 0===c)return g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b];if(f=typeof c,"string"===f&&(e=Qb.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(m.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||m.cssNumber[h]||(c+="px"),k.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),!(g&&"set"in g&&void 0===(c=g.set(a,c,d)))))try{i[b]=c}catch(j){}}},css:function(a,b,c,d){var e,f,g,h=m.camelCase(b);return b=m.cssProps[h]||(m.cssProps[h]=Ub(a.style,h)),g=m.cssHooks[b]||m.cssHooks[h],g&&"get"in g&&(f=g.get(a,!0,c)),void 0===f&&(f=Jb(a,b,d)),"normal"===f&&b in Sb&&(f=Sb[b]),""===c||c?(e=parseFloat(f),c===!0||m.isNumeric(e)?e||0:f):f}}),m.each(["height","width"],function(a,b){m.cssHooks[b]={get:function(a,c,d){return c?Ob.test(m.css(a,"display"))&&0===a.offsetWidth?m.swap(a,Rb,function(){return Yb(a,b,d)}):Yb(a,b,d):void 0},set:function(a,c,d){var e=d&&Ib(a);return Wb(a,c,d?Xb(a,b,d,k.boxSizing&&"border-box"===m.css(a,"boxSizing",!1,e),e):0)}}}),k.opacity||(m.cssHooks.opacity={get:function(a,b){return Nb.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=m.isNumeric(b)?"alpha(opacity="+100*b+")":"",f=d&&d.filter||c.filter||"";c.zoom=1,(b>=1||""===b)&&""===m.trim(f.replace(Mb,""))&&c.removeAttribute&&(c.removeAttribute("filter"),""===b||d&&!d.filter)||(c.filter=Mb.test(f)?f.replace(Mb,e):f+" "+e)}}),m.cssHooks.marginRight=Lb(k.reliableMarginRight,function(a,b){return b?m.swap(a,{display:"inline-block"},Jb,[a,"marginRight"]):void 0}),m.each({margin:"",padding:"",border:"Width"},function(a,b){m.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+T[d]+b]=f[d]||f[d-2]||f[0];return e}},Gb.test(a)||(m.cssHooks[a+b].set=Wb)}),m.fn.extend({css:function(a,b){return V(this,function(a,b,c){var d,e,f={},g=0;if(m.isArray(b)){for(d=Ib(a),e=b.length;e>g;g++)f[b[g]]=m.css(a,b[g],!1,d);return f}return void 0!==c?m.style(a,b,c):m.css(a,b)},a,b,arguments.length>1)},show:function(){return Vb(this,!0)},hide:function(){return Vb(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){U(this)?m(this).show():m(this).hide()})}});function Zb(a,b,c,d,e){return new Zb.prototype.init(a,b,c,d,e)}m.Tween=Zb,Zb.prototype={constructor:Zb,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(m.cssNumber[c]?"":"px")
|
| 4 |
+
},cur:function(){var a=Zb.propHooks[this.prop];return a&&a.get?a.get(this):Zb.propHooks._default.get(this)},run:function(a){var b,c=Zb.propHooks[this.prop];return this.pos=b=this.options.duration?m.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Zb.propHooks._default.set(this),this}},Zb.prototype.init.prototype=Zb.prototype,Zb.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=m.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){m.fx.step[a.prop]?m.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[m.cssProps[a.prop]]||m.cssHooks[a.prop])?m.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Zb.propHooks.scrollTop=Zb.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},m.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},m.fx=Zb.prototype.init,m.fx.step={};var $b,_b,ac=/^(?:toggle|show|hide)$/,bc=new RegExp("^(?:([+-])=|)("+S+")([a-z%]*)$","i"),cc=/queueHooks$/,dc=[ic],ec={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=bc.exec(b),f=e&&e[3]||(m.cssNumber[a]?"":"px"),g=(m.cssNumber[a]||"px"!==f&&+d)&&bc.exec(m.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,m.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function fc(){return setTimeout(function(){$b=void 0}),$b=m.now()}function gc(a,b){var c,d={height:a},e=0;for(b=b?1:0;4>e;e+=2-b)c=T[e],d["margin"+c]=d["padding"+c]=a;return b&&(d.opacity=d.width=a),d}function hc(a,b,c){for(var d,e=(ec[b]||[]).concat(ec["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function ic(a,b,c){var d,e,f,g,h,i,j,l,n=this,o={},p=a.style,q=a.nodeType&&U(a),r=m._data(a,"fxshow");c.queue||(h=m._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,n.always(function(){n.always(function(){h.unqueued--,m.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[p.overflow,p.overflowX,p.overflowY],j=m.css(a,"display"),l="none"===j?m._data(a,"olddisplay")||Fb(a.nodeName):j,"inline"===l&&"none"===m.css(a,"float")&&(k.inlineBlockNeedsLayout&&"inline"!==Fb(a.nodeName)?p.zoom=1:p.display="inline-block")),c.overflow&&(p.overflow="hidden",k.shrinkWrapBlocks()||n.always(function(){p.overflow=c.overflow[0],p.overflowX=c.overflow[1],p.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],ac.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(q?"hide":"show")){if("show"!==e||!r||void 0===r[d])continue;q=!0}o[d]=r&&r[d]||m.style(a,d)}else j=void 0;if(m.isEmptyObject(o))"inline"===("none"===j?Fb(a.nodeName):j)&&(p.display=j);else{r?"hidden"in r&&(q=r.hidden):r=m._data(a,"fxshow",{}),f&&(r.hidden=!q),q?m(a).show():n.done(function(){m(a).hide()}),n.done(function(){var b;m._removeData(a,"fxshow");for(b in o)m.style(a,b,o[b])});for(d in o)g=hc(q?r[d]:0,d,n),d in r||(r[d]=g.start,q&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function jc(a,b){var c,d,e,f,g;for(c in a)if(d=m.camelCase(c),e=b[d],f=a[c],m.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=m.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function kc(a,b,c){var d,e,f=0,g=dc.length,h=m.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=$b||fc(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:m.extend({},b),opts:m.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:$b||fc(),duration:c.duration,tweens:[],createTween:function(b,c){var d=m.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(jc(k,j.opts.specialEasing);g>f;f++)if(d=dc[f].call(j,a,k,j.opts))return d;return m.map(k,hc,j),m.isFunction(j.opts.start)&&j.opts.start.call(a,j),m.fx.timer(m.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}m.Animation=m.extend(kc,{tweener:function(a,b){m.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],ec[c]=ec[c]||[],ec[c].unshift(b)},prefilter:function(a,b){b?dc.unshift(a):dc.push(a)}}),m.speed=function(a,b,c){var d=a&&"object"==typeof a?m.extend({},a):{complete:c||!c&&b||m.isFunction(a)&&a,duration:a,easing:c&&b||b&&!m.isFunction(b)&&b};return d.duration=m.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in m.fx.speeds?m.fx.speeds[d.duration]:m.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){m.isFunction(d.old)&&d.old.call(this),d.queue&&m.dequeue(this,d.queue)},d},m.fn.extend({fadeTo:function(a,b,c,d){return this.filter(U).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=m.isEmptyObject(a),f=m.speed(b,c,d),g=function(){var b=kc(this,m.extend({},a),f);(e||m._data(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=m.timers,g=m._data(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&cc.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&m.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=m._data(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=m.timers,g=d?d.length:0;for(c.finish=!0,m.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),m.each(["toggle","show","hide"],function(a,b){var c=m.fn[b];m.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(gc(b,!0),a,d,e)}}),m.each({slideDown:gc("show"),slideUp:gc("hide"),slideToggle:gc("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){m.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),m.timers=[],m.fx.tick=function(){var a,b=m.timers,c=0;for($b=m.now();c<b.length;c++)a=b[c],a()||b[c]!==a||b.splice(c--,1);b.length||m.fx.stop(),$b=void 0},m.fx.timer=function(a){m.timers.push(a),a()?m.fx.start():m.timers.pop()},m.fx.interval=13,m.fx.start=function(){_b||(_b=setInterval(m.fx.tick,m.fx.interval))},m.fx.stop=function(){clearInterval(_b),_b=null},m.fx.speeds={slow:600,fast:200,_default:400},m.fn.delay=function(a,b){return a=m.fx?m.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a,b,c,d,e;b=y.createElement("div"),b.setAttribute("className","t"),b.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",d=b.getElementsByTagName("a")[0],c=y.createElement("select"),e=c.appendChild(y.createElement("option")),a=b.getElementsByTagName("input")[0],d.style.cssText="top:1px",k.getSetAttribute="t"!==b.className,k.style=/top/.test(d.getAttribute("style")),k.hrefNormalized="/a"===d.getAttribute("href"),k.checkOn=!!a.value,k.optSelected=e.selected,k.enctype=!!y.createElement("form").enctype,c.disabled=!0,k.optDisabled=!e.disabled,a=y.createElement("input"),a.setAttribute("value",""),k.input=""===a.getAttribute("value"),a.value="t",a.setAttribute("type","radio"),k.radioValue="t"===a.value}();var lc=/\r/g;m.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=m.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,m(this).val()):a,null==e?e="":"number"==typeof e?e+="":m.isArray(e)&&(e=m.map(e,function(a){return null==a?"":a+""})),b=m.valHooks[this.type]||m.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=m.valHooks[e.type]||m.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(lc,""):null==c?"":c)}}}),m.extend({valHooks:{option:{get:function(a){var b=m.find.attr(a,"value");return null!=b?b:m.trim(m.text(a))}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],!(!c.selected&&i!==e||(k.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.parentNode.disabled&&m.nodeName(c.parentNode,"optgroup"))){if(b=m(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=m.makeArray(b),g=e.length;while(g--)if(d=e[g],m.inArray(m.valHooks.option.get(d),f)>=0)try{d.selected=c=!0}catch(h){d.scrollHeight}else d.selected=!1;return c||(a.selectedIndex=-1),e}}}}),m.each(["radio","checkbox"],function(){m.valHooks[this]={set:function(a,b){return m.isArray(b)?a.checked=m.inArray(m(a).val(),b)>=0:void 0}},k.checkOn||(m.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var mc,nc,oc=m.expr.attrHandle,pc=/^(?:checked|selected)$/i,qc=k.getSetAttribute,rc=k.input;m.fn.extend({attr:function(a,b){return V(this,m.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){m.removeAttr(this,a)})}}),m.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===K?m.prop(a,b,c):(1===f&&m.isXMLDoc(a)||(b=b.toLowerCase(),d=m.attrHooks[b]||(m.expr.match.bool.test(b)?nc:mc)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=m.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void m.removeAttr(a,b))},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(E);if(f&&1===a.nodeType)while(c=f[e++])d=m.propFix[c]||c,m.expr.match.bool.test(c)?rc&&qc||!pc.test(c)?a[d]=!1:a[m.camelCase("default-"+c)]=a[d]=!1:m.attr(a,c,""),a.removeAttribute(qc?c:d)},attrHooks:{type:{set:function(a,b){if(!k.radioValue&&"radio"===b&&m.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),nc={set:function(a,b,c){return b===!1?m.removeAttr(a,c):rc&&qc||!pc.test(c)?a.setAttribute(!qc&&m.propFix[c]||c,c):a[m.camelCase("default-"+c)]=a[c]=!0,c}},m.each(m.expr.match.bool.source.match(/\w+/g),function(a,b){var c=oc[b]||m.find.attr;oc[b]=rc&&qc||!pc.test(b)?function(a,b,d){var e,f;return d||(f=oc[b],oc[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,oc[b]=f),e}:function(a,b,c){return c?void 0:a[m.camelCase("default-"+b)]?b.toLowerCase():null}}),rc&&qc||(m.attrHooks.value={set:function(a,b,c){return m.nodeName(a,"input")?void(a.defaultValue=b):mc&&mc.set(a,b,c)}}),qc||(mc={set:function(a,b,c){var d=a.getAttributeNode(c);return d||a.setAttributeNode(d=a.ownerDocument.createAttribute(c)),d.value=b+="","value"===c||b===a.getAttribute(c)?b:void 0}},oc.id=oc.name=oc.coords=function(a,b,c){var d;return c?void 0:(d=a.getAttributeNode(b))&&""!==d.value?d.value:null},m.valHooks.button={get:function(a,b){var c=a.getAttributeNode(b);return c&&c.specified?c.value:void 0},set:mc.set},m.attrHooks.contenteditable={set:function(a,b,c){mc.set(a,""===b?!1:b,c)}},m.each(["width","height"],function(a,b){m.attrHooks[b]={set:function(a,c){return""===c?(a.setAttribute(b,"auto"),c):void 0}}})),k.style||(m.attrHooks.style={get:function(a){return a.style.cssText||void 0},set:function(a,b){return a.style.cssText=b+""}});var sc=/^(?:input|select|textarea|button|object)$/i,tc=/^(?:a|area)$/i;m.fn.extend({prop:function(a,b){return V(this,m.prop,a,b,arguments.length>1)},removeProp:function(a){return a=m.propFix[a]||a,this.each(function(){try{this[a]=void 0,delete this[a]}catch(b){}})}}),m.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!m.isXMLDoc(a),f&&(b=m.propFix[b]||b,e=m.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=m.find.attr(a,"tabindex");return b?parseInt(b,10):sc.test(a.nodeName)||tc.test(a.nodeName)&&a.href?0:-1}}}}),k.hrefNormalized||m.each(["href","src"],function(a,b){m.propHooks[b]={get:function(a){return a.getAttribute(b,4)}}}),k.optSelected||(m.propHooks.selected={get:function(a){var b=a.parentNode;return b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex),null}}),m.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){m.propFix[this.toLowerCase()]=this}),k.enctype||(m.propFix.enctype="encoding");var uc=/[\t\r\n\f]/g;m.fn.extend({addClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j="string"==typeof a&&a;if(m.isFunction(a))return this.each(function(b){m(this).addClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(E)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(uc," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=m.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0,i=this.length,j=0===arguments.length||"string"==typeof a&&a;if(m.isFunction(a))return this.each(function(b){m(this).removeClass(a.call(this,b,this.className))});if(j)for(b=(a||"").match(E)||[];i>h;h++)if(c=this[h],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(uc," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?m.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(m.isFunction(a)?function(c){m(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=m(this),f=a.match(E)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===K||"boolean"===c)&&(this.className&&m._data(this,"__className__",this.className),this.className=this.className||a===!1?"":m._data(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(uc," ").indexOf(b)>=0)return!0;return!1}}),m.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){m.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),m.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}});var vc=m.now(),wc=/\?/,xc=/(,)|(\[|{)|(}|])|"(?:[^"\\\r\n]|\\["\\\/bfnrt]|\\u[\da-fA-F]{4})*"\s*:?|true|false|null|-?(?!0\d)\d+(?:\.\d+|)(?:[eE][+-]?\d+|)/g;m.parseJSON=function(b){if(a.JSON&&a.JSON.parse)return a.JSON.parse(b+"");var c,d=null,e=m.trim(b+"");return e&&!m.trim(e.replace(xc,function(a,b,e,f){return c&&b&&(d=0),0===d?a:(c=e||b,d+=!f-!e,"")}))?Function("return "+e)():m.error("Invalid JSON: "+b)},m.parseXML=function(b){var c,d;if(!b||"string"!=typeof b)return null;try{a.DOMParser?(d=new DOMParser,c=d.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b))}catch(e){c=void 0}return c&&c.documentElement&&!c.getElementsByTagName("parsererror").length||m.error("Invalid XML: "+b),c};var yc,zc,Ac=/#.*$/,Bc=/([?&])_=[^&]*/,Cc=/^(.*?):[ \t]*([^\r\n]*)\r?$/gm,Dc=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Ec=/^(?:GET|HEAD)$/,Fc=/^\/\//,Gc=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,Hc={},Ic={},Jc="*/".concat("*");try{zc=location.href}catch(Kc){zc=y.createElement("a"),zc.href="",zc=zc.href}yc=Gc.exec(zc.toLowerCase())||[];function Lc(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(E)||[];if(m.isFunction(c))while(d=f[e++])"+"===d.charAt(0)?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Mc(a,b,c,d){var e={},f=a===Ic;function g(h){var i;return e[h]=!0,m.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function Nc(a,b){var c,d,e=m.ajaxSettings.flatOptions||{};for(d in b)void 0!==b[d]&&((e[d]?a:c||(c={}))[d]=b[d]);return c&&m.extend(!0,a,c),a}function Oc(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===e&&(e=a.mimeType||b.getResponseHeader("Content-Type"));if(e)for(g in h)if(h[g]&&h[g].test(e)){i.unshift(g);break}if(i[0]in c)f=i[0];else{for(g in c){if(!i[0]||a.converters[g+" "+i[0]]){f=g;break}d||(d=g)}f=f||d}return f?(f!==i[0]&&i.unshift(f),c[f]):void 0}function Pc(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}m.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:zc,type:"GET",isLocal:Dc.test(yc[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Jc,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":m.parseJSON,"text xml":m.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Nc(Nc(a,m.ajaxSettings),b):Nc(m.ajaxSettings,a)},ajaxPrefilter:Lc(Hc),ajaxTransport:Lc(Ic),ajax:function(a,b){"object"==typeof a&&(b=a,a=void 0),b=b||{};var c,d,e,f,g,h,i,j,k=m.ajaxSetup({},b),l=k.context||k,n=k.context&&(l.nodeType||l.jquery)?m(l):m.event,o=m.Deferred(),p=m.Callbacks("once memory"),q=k.statusCode||{},r={},s={},t=0,u="canceled",v={readyState:0,getResponseHeader:function(a){var b;if(2===t){if(!j){j={};while(b=Cc.exec(f))j[b[1].toLowerCase()]=b[2]}b=j[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return 2===t?f:null},setRequestHeader:function(a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this},overrideMimeType:function(a){return t||(k.mimeType=a),this},statusCode:function(a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this},abort:function(a){var b=a||u;return i&&i.abort(b),x(0,b),this}};if(o.promise(v).complete=p.add,v.success=v.done,v.error=v.fail,k.url=((a||k.url||zc)+"").replace(Ac,"").replace(Fc,yc[1]+"//"),k.type=b.method||b.type||k.method||k.type,k.dataTypes=m.trim(k.dataType||"*").toLowerCase().match(E)||[""],null==k.crossDomain&&(c=Gc.exec(k.url.toLowerCase()),k.crossDomain=!(!c||c[1]===yc[1]&&c[2]===yc[2]&&(c[3]||("http:"===c[1]?"80":"443"))===(yc[3]||("http:"===yc[1]?"80":"443")))),k.data&&k.processData&&"string"!=typeof k.data&&(k.data=m.param(k.data,k.traditional)),Mc(Hc,k,b,v),2===t)return v;h=k.global,h&&0===m.active++&&m.event.trigger("ajaxStart"),k.type=k.type.toUpperCase(),k.hasContent=!Ec.test(k.type),e=k.url,k.hasContent||(k.data&&(e=k.url+=(wc.test(e)?"&":"?")+k.data,delete k.data),k.cache===!1&&(k.url=Bc.test(e)?e.replace(Bc,"$1_="+vc++):e+(wc.test(e)?"&":"?")+"_="+vc++)),k.ifModified&&(m.lastModified[e]&&v.setRequestHeader("If-Modified-Since",m.lastModified[e]),m.etag[e]&&v.setRequestHeader("If-None-Match",m.etag[e])),(k.data&&k.hasContent&&k.contentType!==!1||b.contentType)&&v.setRequestHeader("Content-Type",k.contentType),v.setRequestHeader("Accept",k.dataTypes[0]&&k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+Jc+"; q=0.01":""):k.accepts["*"]);for(d in k.headers)v.setRequestHeader(d,k.headers[d]);if(k.beforeSend&&(k.beforeSend.call(l,v,k)===!1||2===t))return v.abort();u="abort";for(d in{success:1,error:1,complete:1})v[d](k[d]);if(i=Mc(Ic,k,b,v)){v.readyState=1,h&&n.trigger("ajaxSend",[v,k]),k.async&&k.timeout>0&&(g=setTimeout(function(){v.abort("timeout")},k.timeout));try{t=1,i.send(r,x)}catch(w){if(!(2>t))throw w;x(-1,w)}}else x(-1,"No Transport");function x(a,b,c,d){var j,r,s,u,w,x=b;2!==t&&(t=2,g&&clearTimeout(g),i=void 0,f=d||"",v.readyState=a>0?4:0,j=a>=200&&300>a||304===a,c&&(u=Oc(k,v,c)),u=Pc(k,u,v,j),j?(k.ifModified&&(w=v.getResponseHeader("Last-Modified"),w&&(m.lastModified[e]=w),w=v.getResponseHeader("etag"),w&&(m.etag[e]=w)),204===a||"HEAD"===k.type?x="nocontent":304===a?x="notmodified":(x=u.state,r=u.data,s=u.error,j=!s)):(s=x,(a||!x)&&(x="error",0>a&&(a=0))),v.status=a,v.statusText=(b||x)+"",j?o.resolveWith(l,[r,x,v]):o.rejectWith(l,[v,x,s]),v.statusCode(q),q=void 0,h&&n.trigger(j?"ajaxSuccess":"ajaxError",[v,k,j?r:s]),p.fireWith(l,[v,x]),h&&(n.trigger("ajaxComplete",[v,k]),--m.active||m.event.trigger("ajaxStop")))}return v},getJSON:function(a,b,c){return m.get(a,b,c,"json")},getScript:function(a,b){return m.get(a,void 0,b,"script")}}),m.each(["get","post"],function(a,b){m[b]=function(a,c,d,e){return m.isFunction(c)&&(e=e||d,d=c,c=void 0),m.ajax({url:a,type:b,dataType:e,data:c,success:d})}}),m.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){m.fn[b]=function(a){return this.on(b,a)}}),m._evalUrl=function(a){return m.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},m.fn.extend({wrapAll:function(a){if(m.isFunction(a))return this.each(function(b){m(this).wrapAll(a.call(this,b))});if(this[0]){var b=m(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&1===a.firstChild.nodeType)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){return this.each(m.isFunction(a)?function(b){m(this).wrapInner(a.call(this,b))}:function(){var b=m(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=m.isFunction(a);return this.each(function(c){m(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){m.nodeName(this,"body")||m(this).replaceWith(this.childNodes)}).end()}}),m.expr.filters.hidden=function(a){return a.offsetWidth<=0&&a.offsetHeight<=0||!k.reliableHiddenOffsets()&&"none"===(a.style&&a.style.display||m.css(a,"display"))},m.expr.filters.visible=function(a){return!m.expr.filters.hidden(a)};var Qc=/%20/g,Rc=/\[\]$/,Sc=/\r?\n/g,Tc=/^(?:submit|button|image|reset|file)$/i,Uc=/^(?:input|select|textarea|keygen)/i;function Vc(a,b,c,d){var e;if(m.isArray(b))m.each(b,function(b,e){c||Rc.test(a)?d(a,e):Vc(a+"["+("object"==typeof e?b:"")+"]",e,c,d)});else if(c||"object"!==m.type(b))d(a,b);else for(e in b)Vc(a+"["+e+"]",b[e],c,d)}m.param=function(a,b){var c,d=[],e=function(a,b){b=m.isFunction(b)?b():null==b?"":b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};if(void 0===b&&(b=m.ajaxSettings&&m.ajaxSettings.traditional),m.isArray(a)||a.jquery&&!m.isPlainObject(a))m.each(a,function(){e(this.name,this.value)});else for(c in a)Vc(c,a[c],b,e);return d.join("&").replace(Qc,"+")},m.fn.extend({serialize:function(){return m.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=m.prop(this,"elements");return a?m.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!m(this).is(":disabled")&&Uc.test(this.nodeName)&&!Tc.test(a)&&(this.checked||!W.test(a))}).map(function(a,b){var c=m(this).val();return null==c?null:m.isArray(c)?m.map(c,function(a){return{name:b.name,value:a.replace(Sc,"\r\n")}}):{name:b.name,value:c.replace(Sc,"\r\n")}}).get()}}),m.ajaxSettings.xhr=void 0!==a.ActiveXObject?function(){return!this.isLocal&&/^(get|post|head|put|delete|options)$/i.test(this.type)&&Zc()||$c()}:Zc;var Wc=0,Xc={},Yc=m.ajaxSettings.xhr();a.ActiveXObject&&m(a).on("unload",function(){for(var a in Xc)Xc[a](void 0,!0)}),k.cors=!!Yc&&"withCredentials"in Yc,Yc=k.ajax=!!Yc,Yc&&m.ajaxTransport(function(a){if(!a.crossDomain||k.cors){var b;return{send:function(c,d){var e,f=a.xhr(),g=++Wc;if(f.open(a.type,a.url,a.async,a.username,a.password),a.xhrFields)for(e in a.xhrFields)f[e]=a.xhrFields[e];a.mimeType&&f.overrideMimeType&&f.overrideMimeType(a.mimeType),a.crossDomain||c["X-Requested-With"]||(c["X-Requested-With"]="XMLHttpRequest");for(e in c)void 0!==c[e]&&f.setRequestHeader(e,c[e]+"");f.send(a.hasContent&&a.data||null),b=function(c,e){var h,i,j;if(b&&(e||4===f.readyState))if(delete Xc[g],b=void 0,f.onreadystatechange=m.noop,e)4!==f.readyState&&f.abort();else{j={},h=f.status,"string"==typeof f.responseText&&(j.text=f.responseText);try{i=f.statusText}catch(k){i=""}h||!a.isLocal||a.crossDomain?1223===h&&(h=204):h=j.text?200:404}j&&d(h,i,j,f.getAllResponseHeaders())},a.async?4===f.readyState?setTimeout(b):f.onreadystatechange=Xc[g]=b:b()},abort:function(){b&&b(void 0,!0)}}}});function Zc(){try{return new a.XMLHttpRequest}catch(b){}}function $c(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}m.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return m.globalEval(a),a}}}),m.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),m.ajaxTransport("script",function(a){if(a.crossDomain){var b,c=y.head||m("head")[0]||y.documentElement;return{send:function(d,e){b=y.createElement("script"),b.async=!0,a.scriptCharset&&(b.charset=a.scriptCharset),b.src=a.url,b.onload=b.onreadystatechange=function(a,c){(c||!b.readyState||/loaded|complete/.test(b.readyState))&&(b.onload=b.onreadystatechange=null,b.parentNode&&b.parentNode.removeChild(b),b=null,c||e(200,"success"))},c.insertBefore(b,c.firstChild)},abort:function(){b&&b.onload(void 0,!0)}}}});var _c=[],ad=/(=)\?(?=&|$)|\?\?/;m.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=_c.pop()||m.expando+"_"+vc++;return this[a]=!0,a}}),m.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(ad.test(b.url)?"url":"string"==typeof b.data&&!(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&ad.test(b.data)&&"data");return h||"jsonp"===b.dataTypes[0]?(e=b.jsonpCallback=m.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(ad,"$1"+e):b.jsonp!==!1&&(b.url+=(wc.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||m.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,_c.push(e)),g&&m.isFunction(f)&&f(g[0]),g=f=void 0}),"script"):void 0}),m.parseHTML=function(a,b,c){if(!a||"string"!=typeof a)return null;"boolean"==typeof b&&(c=b,b=!1),b=b||y;var d=u.exec(a),e=!c&&[];return d?[b.createElement(d[1])]:(d=m.buildFragment([a],b,e),e&&e.length&&m(e).remove(),m.merge([],d.childNodes))};var bd=m.fn.load;m.fn.load=function(a,b,c){if("string"!=typeof a&&bd)return bd.apply(this,arguments);var d,e,f,g=this,h=a.indexOf(" ");return h>=0&&(d=m.trim(a.slice(h,a.length)),a=a.slice(0,h)),m.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(f="POST"),g.length>0&&m.ajax({url:a,type:f,dataType:"html",data:b}).done(function(a){e=arguments,g.html(d?m("<div>").append(m.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,e||[a.responseText,b,a])}),this},m.expr.filters.animated=function(a){return m.grep(m.timers,function(b){return a===b.elem}).length};var cd=a.document.documentElement;function dd(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1}m.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=m.css(a,"position"),l=m(a),n={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=m.css(a,"top"),i=m.css(a,"left"),j=("absolute"===k||"fixed"===k)&&m.inArray("auto",[f,i])>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),m.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(n.top=b.top-h.top+g),null!=b.left&&(n.left=b.left-h.left+e),"using"in b?b.using.call(a,n):l.css(n)}},m.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){m.offset.setOffset(this,a,b)});var b,c,d={top:0,left:0},e=this[0],f=e&&e.ownerDocument;if(f)return b=f.documentElement,m.contains(b,e)?(typeof e.getBoundingClientRect!==K&&(d=e.getBoundingClientRect()),c=dd(f),{top:d.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:d.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):d},position:function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===m.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),m.nodeName(a[0],"html")||(c=a.offset()),c.top+=m.css(a[0],"borderTopWidth",!0),c.left+=m.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-m.css(d,"marginTop",!0),left:b.left-c.left-m.css(d,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||cd;while(a&&!m.nodeName(a,"html")&&"static"===m.css(a,"position"))a=a.offsetParent;return a||cd})}}),m.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);m.fn[a]=function(d){return V(this,function(a,d,e){var f=dd(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?m(f).scrollLeft():e,c?e:m(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}),m.each(["top","left"],function(a,b){m.cssHooks[b]=Lb(k.pixelPosition,function(a,c){return c?(c=Jb(a,b),Hb.test(c)?m(a).position()[b]+"px":c):void 0})}),m.each({Height:"height",Width:"width"},function(a,b){m.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){m.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return V(this,function(b,c,d){var e;return m.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?m.css(b,c,g):m.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),m.fn.size=function(){return this.length},m.fn.andSelf=m.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return m});var ed=a.jQuery,fd=a.$;return m.noConflict=function(b){return a.$===m&&(a.$=fd),b&&a.jQuery===m&&(a.jQuery=ed),m},typeof b===K&&(a.jQuery=a.$=m),m});
|
| 5 |
+
jQuery.noConflict();
|
skin/frontend/default/default/monstroestudio/moip/js/moip-form.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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TMLEvents');
|
| 6 |
+
evt.initEvent(eventName, true, true);
|
| 7 |
+
|
| 8 |
+
return this.dispatchEvent(evt);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
if (this.fireEvent)
|
| 12 |
+
return this.fireEvent('on' + eventName);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
Ajax.Responders.register({
|
| 16 |
+
onComplete: ajaxActions
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
function ajaxActions() {
|
| 20 |
+
doMasks();
|
| 21 |
+
doTabs();
|
| 22 |
+
doBandeiras();
|
| 23 |
+
doSafe();
|
| 24 |
+
}
|
| 25 |
+
function adjustStreetLines(){
|
| 26 |
+
if($$('input[name="billing[street][]"]').length == 4 && $$('input[name="billing[street][]"] label').length < 4){
|
| 27 |
+
var counter = 0;
|
| 28 |
+
$$('input[name="billing[street][]"]').each(function(element){
|
| 29 |
+
element.up(1).removeClassName('wide').addClassName('field');
|
| 30 |
+
switch(counter){
|
| 31 |
+
case 0:
|
| 32 |
+
element.up(1).down('label').innerHTML = '<em>*</em>Rua';
|
| 33 |
+
break;
|
| 34 |
+
case 1:
|
| 35 |
+
element.addClassName('required-entry');
|
| 36 |
+
element.up(1).innerHTML = '<label for="billing:street2" class="required"><em>*</em>Número</label>'+element.up(1).innerHTML;
|
| 37 |
+
break;
|
| 38 |
+
case 2:
|
| 39 |
+
element.up(1).innerHTML = '<label for="billing:street3" >Complemento</label>'+element.up(1).innerHTML;
|
| 40 |
+
break;
|
| 41 |
+
case 3:
|
| 42 |
+
element.addClassName('required-entry');
|
| 43 |
+
element.up(1).innerHTML = '<label for="billing:street4" class="required"><em>*</em>Bairro</label>'+element.up(1).innerHTML;
|
| 44 |
+
break;
|
| 45 |
+
}
|
| 46 |
+
counter++;
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function validateCVV(element) {
|
| 52 |
+
if (element.value.length >= 3) {
|
| 53 |
+
$$('#payment_form_moip li.hide').each(function(item) {
|
| 54 |
+
item.slideDown();
|
| 55 |
+
});
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function doSafe() {
|
| 60 |
+
if ($('moip-safe')) {
|
| 61 |
+
if ($('moip-safe').value == 'new') {
|
| 62 |
+
$('moip-safe-cvv-parent').hide();
|
| 63 |
+
$('moip-safe-parcelas-parent').hide();
|
| 64 |
+
$('moip-new-cc-form').show();
|
| 65 |
+
$('moip-new-cc-form').select('input.required').each(function(element) {
|
| 66 |
+
element.addClassName('required-entry');
|
| 67 |
+
});
|
| 68 |
+
$('moip-safe-form').select('input.required').each(function(element) {
|
| 69 |
+
element.removeClassName('required-entry');
|
| 70 |
+
});
|
| 71 |
+
} else {
|
| 72 |
+
$('bandeira-safe').value = $$('#moip-safe option:checked')[0].readAttribute('data-flag');
|
| 73 |
+
$('moip-safe-cvv-parent').show();
|
| 74 |
+
$('moip-safe-parcelas-parent').show();
|
| 75 |
+
$('moip-new-cc-form').hide();
|
| 76 |
+
$('moip-new-cc-form').select('input.required').each(function(element) {
|
| 77 |
+
element.removeClassName('required-entry');
|
| 78 |
+
});
|
| 79 |
+
$('moip-safe-form').select('input.required').each(function(element) {
|
| 80 |
+
element.addClassName('required-entry');
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
$('moip-safe').observe('change', function(event) {
|
| 84 |
+
if ($('moip-safe').value == 'new') {
|
| 85 |
+
$('moip-safe-cvv-parent').hide();
|
| 86 |
+
$('moip-safe-parcelas-parent').hide();
|
| 87 |
+
$('moip-new-cc-form').show();
|
| 88 |
+
$('moip-new-cc-form').select('input.required').each(function(element) {
|
| 89 |
+
element.addClassName('required-entry');
|
| 90 |
+
});
|
| 91 |
+
$('moip-safe-form').select('input.required').each(function(element) {
|
| 92 |
+
element.removeClassName('required-entry');
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
} else {
|
| 96 |
+
$('bandeira-safe').value = $$('#moip-safe option:checked')[0].readAttribute('data-flag');
|
| 97 |
+
|
| 98 |
+
switch($$('#moip-safe option:checked')[0].readAttribute('data-flag')){
|
| 99 |
+
case 'AmericanExpress':
|
| 100 |
+
var bandeira = 'amex';
|
| 101 |
+
break;
|
| 102 |
+
case 'Diners':
|
| 103 |
+
var bandeira = 'diners';
|
| 104 |
+
break;
|
| 105 |
+
case 'Mastercard':
|
| 106 |
+
var bandeira = 'master';
|
| 107 |
+
break;
|
| 108 |
+
case 'Hipercard':
|
| 109 |
+
var bandeira = 'hiper';
|
| 110 |
+
break;
|
| 111 |
+
case 'Visa':
|
| 112 |
+
var bandeira = 'visa';
|
| 113 |
+
break;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
$$('input[name="payment[bandeira]"][value="'+bandeira+'"]')[0].triggerEvent('click');
|
| 118 |
+
$('moip-safe-cvv-parent').show();
|
| 119 |
+
$('moip-safe-parcelas-parent').show();
|
| 120 |
+
$('moip-new-cc-form').hide();
|
| 121 |
+
$('moip-new-cc-form').select('input.required').each(function(element) {
|
| 122 |
+
element.removeClassName('required-entry');
|
| 123 |
+
});
|
| 124 |
+
$('moip-safe-form').select('input.required').each(function(element) {
|
| 125 |
+
element.addClassName('required-entry');
|
| 126 |
+
});
|
| 127 |
+
}
|
| 128 |
+
});
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function doBandeiras() {
|
| 133 |
+
$$('ul.form-list .wide.bandeira > label').each(function(element) {
|
| 134 |
+
element.observe('click', function(event) {
|
| 135 |
+
var obj = this;
|
| 136 |
+
if (this.up(0).select('.active')[0]) {
|
| 137 |
+
this.up(0).select('.active')[0].removeClassName('active');
|
| 138 |
+
}
|
| 139 |
+
this.select('img')[0].addClassName('active');
|
| 140 |
+
this.select('input')[0].click();
|
| 141 |
+
});
|
| 142 |
+
});
|
| 143 |
+
}
|
| 144 |
+
var cc, validate, cc_holder_cpf, cc_holder_dob, cc_holder_phone, billing_phone;
|
| 145 |
+
|
| 146 |
+
function doMasks() {
|
| 147 |
+
if (cc === undefined || cc.elements.length === 0) {
|
| 148 |
+
cc = new MaskedInput('[id=moip_cc_number]', '9999 9999 9999 99?99 999');
|
| 149 |
+
validade = new MaskedInput('[id=moip_validade]', '99/99');
|
| 150 |
+
cc_holder_cpf = new MaskedInput('[id=moip_cc_holder_cpf]', '999.999.999-99');
|
| 151 |
+
cc_holder_dob = new MaskedInput('[id=moip_cc_holder_dob]', '99/99/9999');
|
| 152 |
+
cc_holder_phone = new MaskedInput('[id=moip_cc_holder_phone]', '(99)9999-9999?9');
|
| 153 |
+
}
|
| 154 |
+
if (billing_phone === undefined || billing_phone.elements.length === 0) {
|
| 155 |
+
billing_phone = new MaskedInput('[id="billing:telephone"]', '(99)9999-9999?9');
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function selectCCType(input) {
|
| 160 |
+
var value = input.value.replace(new RegExp('_', 'g'),'');
|
| 161 |
+
|
| 162 |
+
if (CreditCard.validate(value)) {
|
| 163 |
+
var inputNew = $$('.wide.bandeira input[value=' + CreditCard.type(value) + ']')[0];
|
| 164 |
+
inputNew.click();
|
| 165 |
+
if (inputNew.up(0).select('img')[0] != $$('.wide.bandeira img.active')[0]) {
|
| 166 |
+
if ($$('.wide.bandeira img.active')[0]) {
|
| 167 |
+
$$('.wide.bandeira img.active')[0].removeClassName('active');
|
| 168 |
+
}
|
| 169 |
+
$$('.wide.bandeira input[value=' + CreditCard.type(value) + ']')[0].up(0).select('img')[0].addClassName('active');
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function doTabs() {
|
| 175 |
+
$$('#payment_form_moip .col-left > span').each(function(element) {
|
| 176 |
+
if (!element.hasClassName('injected')) {
|
| 177 |
+
element.addClassName('injected')
|
| 178 |
+
element.observe('click', function(event) {
|
| 179 |
+
//Button
|
| 180 |
+
var button = this;
|
| 181 |
+
$$('#payment_form_moip .col-left > span').each(function(element) {
|
| 182 |
+
if (button != element) {
|
| 183 |
+
element.removeClassName('active');
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
button.addClassName('active');
|
| 187 |
+
//Container
|
| 188 |
+
var target = button.readAttribute('data-target');
|
| 189 |
+
var targetElement = $$('[data-name=' + target + ']')[0];
|
| 190 |
+
var currentTab = $$('.moip-payment-method.active')[0];
|
| 191 |
+
$('moip_moip_method').value = target;
|
| 192 |
+
if (targetElement != currentTab) {
|
| 193 |
+
currentTab.removeClassName('active');
|
| 194 |
+
currentTab.slideUp();
|
| 195 |
+
currentTab.select('input.required').each(function(element) {
|
| 196 |
+
element.removeClassName('required-entry');
|
| 197 |
+
});
|
| 198 |
+
targetElement.addClassName('active').slideDown();
|
| 199 |
+
targetElement.select('input.required').each(function(element) {
|
| 200 |
+
element.addClassName('required-entry');
|
| 201 |
+
});
|
| 202 |
+
}
|
| 203 |
+
});
|
| 204 |
+
}
|
| 205 |
+
});
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
window.onload = function(){
|
| 209 |
+
adjustStreetLines();
|
| 210 |
+
billing_phone = new MaskedInput('[id="billing:telephone"]', '(99)9999-9999?9');
|
| 211 |
+
}
|
skin/frontend/default/default/monstroestudio/moip/js/prototype.maskedinput.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
(function(){var pasteEventName=(Prototype.Browser.IE?'paste':'input'),iPhone=(window.orientation!=undefined);if(typeof(Prototype)=="undefined")
|
| 3 |
+
throw"MaskedInput requires Prototype to be loaded.";Element.addMethods({caret:function(element,begin,end){if(element.length==0)return;if(typeof begin=='number'){end=(typeof end=='number')?end:begin;if(element.setSelectionRange){element.focus();element.setSelectionRange(begin,end);}else if(element.createTextRange){var range=element.createTextRange();range.collapse(true);range.moveEnd('character',end);range.moveStart('character',begin);range.select();}}else{if(element.setSelectionRange){begin=element.selectionStart;end=element.selectionEnd;}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();begin=0-range.duplicate().moveStart('character',-100000);end=begin+range.text.length;}
|
| 4 |
+
return{begin:begin,end:end};}}});MaskedInput=Class.create({initialize:function(selector,mask,settings){this.elements=$$(selector);this.mask(mask,settings);},unmask:function(){this.elements.each(function(el){el.fire("mask:unmask");});return this;},mask:function(mask,settings){if(!mask&&this.elements.length>0){var input=$(this.elements[0]);var tests=input.retrieve("tests");return $A(input.retrieve("buffer")).map(function(c,i){return tests[i]?c:null;}).join('');}
|
| 5 |
+
settings=Object.extend({placeholder:"_",completed:null},settings||{});var defs=MaskedInput.definitions;var tests=[];var partialPosition=mask.length;var firstNonMaskPos=null;var len=mask.length;$A(mask.split("")).each(function(c,i){if(c=='?'){len--;partialPosition=i;}else if(defs[c]){tests.push(new RegExp(defs[c]));if(firstNonMaskPos==null)
|
| 6 |
+
firstNonMaskPos=tests.length-1;}else{tests.push(null);}});this.elements.each(function(el){var input=$(el);var buffer=$A(mask.replace(/\?/,'').split("")).map(function(c,i){return defs[c]?settings.placeholder:c});var ignore=false;var focusText=input.getValue();input.store("buffer",buffer).store("tests",tests);function seekNext(pos){while(++pos<len&&!tests[pos]);return pos;};function shiftL(pos){while(!tests[pos]&&--pos>=0);for(var i=pos;i<len;i++){if(tests[i]){buffer[i]=settings.placeholder;var j=seekNext(i);if(j<len&&tests[i].test(buffer[j])){buffer[i]=buffer[j];}else
|
| 7 |
+
break;}}
|
| 8 |
+
writeBuffer();input.caret(Math.max(firstNonMaskPos,pos));};function shiftR(pos){for(var i=pos,c=settings.placeholder;i<len;i++){if(tests[i]){var j=seekNext(i);var t=buffer[i];buffer[i]=c;if(j<len&&tests[j].test(t))
|
| 9 |
+
c=t;else
|
| 10 |
+
break;}}};function keydownEvent(e){var pos=input.caret();var k=e.keyCode;ignore=(k<16||(k>16&&k<32)||(k>32&&k<41));if((pos.begin-pos.end)!=0&&(!ignore||k==8||k==46))
|
| 11 |
+
clearBuffer(pos.begin,pos.end);if(k==8||k==46||(iPhone&&k==127)){shiftL(pos.begin+(k==46?0:-1));e.stop();}else if(k==27){input.setValue(focusText);input.caret(0,checkVal());e.stop();}};function keypressEvent(e){if(ignore){ignore=false;return(e.keyCode==8)?false:null;}
|
| 12 |
+
e=e||window.event;var k=e.charCode||e.keyCode||e.which;var pos=input.caret();if(e.ctrlKey||e.altKey||e.metaKey){return true;}else if((k>=32&&k<=125)||k>186){var p=seekNext(pos.begin-1);if(p<len){var c=String.fromCharCode(k);if(tests[p].test(c)){shiftR(p);buffer[p]=c;writeBuffer();var next=seekNext(p);input.caret(next);if(settings.completed&&next==len)
|
| 13 |
+
settings.completed.call(input);}}}
|
| 14 |
+
e.stop();};function blurEvent(e){checkVal();if(input.getValue()!=focusText){if(window.Event.simulate){input.simulate('change');}}};function focusEvent(e){focusText=input.getValue();var pos=checkVal();writeBuffer();setTimeout(function(){if(pos==mask.length)
|
| 15 |
+
input.caret(0,pos);else
|
| 16 |
+
input.caret(pos);},0);};function pasteEvent(e){setTimeout(function(){input.caret(checkVal(true));},0);};function clearBuffer(start,end){for(var i=start;i<end&&i<len;i++){if(tests[i])
|
| 17 |
+
buffer[i]=settings.placeholder;}};function writeBuffer(){return input.setValue(buffer.join('')).getValue();};function checkVal(allow){var test=input.getValue();var lastMatch=-1;for(var i=0,pos=0;i<len;i++){if(tests[i]){buffer[i]=settings.placeholder;while(pos++<test.length){var c=test.charAt(pos-1);if(tests[i].test(c)){buffer[i]=c;lastMatch=i;break;}}
|
| 18 |
+
if(pos>test.length)
|
| 19 |
+
break;}else if(buffer[i]==test[pos]&&i!=partialPosition){pos++;lastMatch=i;}}
|
| 20 |
+
if(!allow&&lastMatch+1<partialPosition){input.setValue("");clearBuffer(0,len);}else if(allow||lastMatch+1>=partialPosition){writeBuffer();if(!allow)input.setValue(input.getValue().substring(0,lastMatch+1));}
|
| 21 |
+
return(partialPosition?i:firstNonMaskPos);};if(!input.readAttribute("readonly"))
|
| 22 |
+
input.observe("mask:unmask",function(){input.store("buffer",undefined).store("tests",undefined).stopObserving("mask:unmask").stopObserving("focus",focusEvent).stopObserving("blur",blurEvent).stopObserving("keydown",keydownEvent).stopObserving("keypress",keypressEvent).stopObserving(pasteEventName,pasteEvent);}).observe("focus",focusEvent).observe("blur",blurEvent).observe("keydown",keydownEvent).observe("keypress",keypressEvent).observe(pasteEventName,pasteEvent);checkVal();});return this;}});Object.extend(MaskedInput,{definitions:{'9':"[0-9]",'a':"[A-Za-z]",'*':"[A-Za-z0-9]"}});})();
|
skin/frontend/default/default/monstroestudio/moip/js/validations.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Validation.add('validar_cpf', 'O CPF ou CNPJ informado é inválido', function(v) {return validarCPF(v);});
|
| 2 |
+
Validation.add('validar_vencimento', 'A data de vencimento é inválida', function(v) {return validaVencimento(v);});
|
| 3 |
+
Validation.add('validar_dob', 'A data de nacimento é inválida', function(v) {return validaDob(v);});
|
| 4 |
+
Validation.add('validar_cvv', 'O seu CVV esta inválido', function(v) {return validaCVV(v);});
|
| 5 |
+
Validation.add('validate-cc-br', 'O número do cartão é inválido', function(v) {return validaCC(v);});
|
| 6 |
+
|
| 7 |
+
function validarCPF(cpf) {
|
| 8 |
+
cpf = cpf.replace(/[^\d]+/g, '');
|
| 9 |
+
if (cpf == '') return false;
|
| 10 |
+
// Elimina CPFs invalidos conhecidos
|
| 11 |
+
if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
|
| 12 |
+
return false;
|
| 13 |
+
// Valida 1o digito
|
| 14 |
+
add = 0;
|
| 15 |
+
for (i = 0; i < 9; i++) add += parseInt(cpf.charAt(i)) * (10 - i); rev = 11 - (add % 11);
|
| 16 |
+
if (rev == 10 || rev == 11) rev = 0;
|
| 17 |
+
if (rev != parseInt(cpf.charAt(9)))
|
| 18 |
+
return false;
|
| 19 |
+
// Valida 2o digito
|
| 20 |
+
add = 0;
|
| 21 |
+
for (i = 0; i < 10; i++) add += parseInt(cpf.charAt(i)) * (11 - i); rev = 11 - (add % 11);
|
| 22 |
+
if (rev == 10 || rev == 11) rev = 0;
|
| 23 |
+
if (rev != parseInt(cpf.charAt(10)))
|
| 24 |
+
return false;
|
| 25 |
+
return true;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function validaVencimento(v){
|
| 29 |
+
var value = v.split('/');
|
| 30 |
+
var today = new Date();
|
| 31 |
+
var month = today.getMonth()+1;
|
| 32 |
+
var year = today.getFullYear();
|
| 33 |
+
year = parseInt(year.toString().substring(2,4));
|
| 34 |
+
if(parseInt(value[1]) < year)
|
| 35 |
+
return false;
|
| 36 |
+
if(parseInt(value[0]) < month && parseInt(value[1]) == year)
|
| 37 |
+
return false;
|
| 38 |
+
return true;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function validaDob(date){
|
| 42 |
+
var dob = date.split('/');
|
| 43 |
+
var currentDate = new Date();
|
| 44 |
+
if(parseInt(dob[0]) > 31 || parseInt(dob[1]) > 12 || parseInt(dob[2]) > (currentDate.getFullYear()-10))
|
| 45 |
+
return false;
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function validaCC(value){
|
| 50 |
+
return CreditCard.validate(value);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function validaCVV(value){
|
| 54 |
+
return Boolean($$('#moip-new-cc-form input[type=radio]:checked')[0].value != 'amex' | ($$('#moip-new-cc-form input[type=radio]:checked')[0].value == 'amex' & value.length==4))
|
| 55 |
+
}
|
