示例#1
0
文件: Publish.php 项目: nabble/ajde
 public function beforeSave(MetaModel $meta, $value, Ajde_Model $model)
 {
     if ($value == 1) {
         // we need to publish this thing
         $stream = $meta->getOption('stream');
         $publisherClass = 'Ajde_Publisher_' . ucfirst($stream);
         /* @var $publisher Ajde_Publisher */
         $publisher = new $publisherClass();
         if (strtolower($stream) == 'twitter') {
             $publisher->setOptions(['consumerKey' => $meta->getOption('twitter_consumerkey'), 'consumerSecret' => $meta->getOption('twitter_consumersecret'), 'token' => $meta->getOption('twitter_token'), 'tokenSecret' => $meta->getOption('twitter_tokensecret')]);
         }
         if (strtolower($stream) == 'mail') {
             $addresses = $model->getPublishRecipients();
             $publisher->setRecipients($addresses);
         }
         // fill with content
         $publishData = $model->getPublishData();
         $publisher->setTitle($publishData['title']);
         $publisher->setMessage($publishData['message']);
         $publisher->setImage($publishData['image']);
         $publisher->setUrl($publishData['url']);
         $value = $publisher->publish();
     }
     return $value;
 }
示例#2
0
 public function validate($options = array())
 {
     $fieldsArray = $this->_model->getTable()->getFieldProperties();
     $fieldOptions = array();
     foreach ($fieldsArray as $fieldName => $fieldProperties) {
         $fieldOptions[$fieldName] = array_merge($fieldProperties, issetor($options[$fieldName], array()));
     }
     $valid = true;
     $errors = array();
     $this->_initValidators($fieldOptions);
     foreach ($this->_model->getValidators() as $fieldName => $fieldValidators) {
         foreach ($fieldValidators as $fieldValidator) {
             /* @var $validator Ajde_Model_ValidatorAbstract */
             $value = null;
             if ($this->_model->has($fieldName)) {
                 $value = $this->_model->get($fieldName);
             }
             $result = $fieldValidator->validate($fieldOptions[$fieldName], $value);
             if ($result['valid'] === false) {
                 if (!isset($errors[$fieldName])) {
                     $errors[$fieldName] = array();
                 }
                 $errors[$fieldName][] = $result['error'];
                 $valid = false;
             }
         }
     }
     $this->_errors = $errors;
     return $valid;
 }
示例#3
0
文件: Item.php 项目: nabble/ajde
 public function setEntity(Ajde_Model $entity)
 {
     try {
         $unitprice = $entity->getUnitprice();
     } catch (Exception $e) {
         // TODO:
         throw new Ajde_Exception("Entity {$entity} does not have a unitprice defined");
     }
     $this->set('entity', $entity->getTable());
     $this->set('entity_id', $entity);
     $this->set('unitprice', $unitprice);
 }
示例#4
0
 public function validate($options = array())
 {
     $fieldsArray = $this->_model->getTable()->getFieldProperties();
     $fieldOptions = array();
     // Add all model fields
     foreach ($fieldsArray as $fieldName => $fieldProperties) {
         $fieldOptions[$fieldName] = array_merge($fieldProperties, isset($options[$fieldName]) ? $options[$fieldName] : array());
         if (isset($options[$fieldName])) {
             unset($options[$fieldName]);
         }
     }
     // Add all non-model fields
     foreach ($options as $fieldName => $fieldProperties) {
         $fieldOptions[$fieldName] = $fieldProperties;
     }
     $valid = true;
     $errors = array();
     $this->_initValidators($fieldOptions);
     foreach ($this->_model->getValidators() as $fieldName => $fieldValidators) {
         foreach ($fieldValidators as $fieldValidator) {
             /* @var $fieldValidator Ajde_Model_ValidatorAbstract */
             $value = null;
             if ($this->_model->has($fieldName)) {
                 $value = $this->_model->get($fieldName);
                 if (is_array($value)) {
                     $value = implode(',', $value);
                 } else {
                     $value = (string) $value;
                 }
             }
             // Only validate when dynamic field is shown
             if ($this->shouldValidateDynamicField($fieldOptions[$fieldName])) {
                 $result = $fieldValidator->validate($fieldOptions[$fieldName], $value);
                 if ($result['valid'] === false) {
                     if (!isset($errors[$fieldName])) {
                         $errors[$fieldName] = array();
                     }
                     $errors[$fieldName][] = $result['error'];
                     $valid = false;
                 }
             }
         }
     }
     $this->_errors = $errors;
     return $valid;
 }
示例#5
0
 public function updatePayment()
 {
     $request = Ajde::app()->getRequest();
     $username = $request->getParam('Username');
     $password = $request->getParam('Password');
     $id = $request->getParam('ID');
     $secret = $request->getParam('Reference');
     $paymentMethod = $request->getParam('PaymentMethod');
     $state = $request->getParam('PaymentState');
     $description = $request->getParam('Description');
     if ($username != Config::get('shopWedealCallbackUsername')) {
         Ajde_Log::log('Invalid username for callback of transaction ' . $secret);
         return false;
     }
     if ($password != Config::get('shopWedealCallbackPassword')) {
         Ajde_Log::log('Invalid password for callback of transaction ' . $secret);
         return false;
     }
     Ajde_Model::register('shop');
     $transaction = new TransactionModel();
     if (!$transaction->loadByField('secret', $secret)) {
         Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
     }
     $request = array("type" => 'query', "merchant" => array("username" => Config::get('shopWedealUsername'), "password" => Config::get('shopWedealPassword'), "reference" => $secret));
     $res = $this->sendRequest($request);
     if ($res['success'] === true) {
         $response = $res['response']->paymentinfo;
         // get transaction details
         if ((int) $response->count == 0) {
             $transaction->payment_status = 'refused';
             $transaction->save();
             Ajde_Log::log('iDeal callback didn\'t return any transaction for ' . $secret);
             return false;
         } elseif (self::isPaid((string) $response->state)) {
             if ((string) $response->id != $id) {
                 Ajde_Log::log('IDs don\'t match for iDeal callback of transaction ' . $secret);
                 return false;
             }
             $details = 'AMOUNT: ' . (string) $response->amount . PHP_EOL . 'PAYER_NAME: ' . (string) $response->consumername . PHP_EOL . 'PAYER_ACCOUNT: ' . (string) $response->consumeraccount . PHP_EOL . 'PAYER_CITY: ' . (string) $response->consumercity . PHP_EOL . 'PAYER_COUNTRY: ' . (string) $response->consumercountry . PHP_EOL . 'WEDEAL_ID: ' . (string) $response->id;
             $transaction->payment_details = $details;
             $transaction->payment_status = 'completed';
             $transaction->save();
             return true;
         } elseif (self::isRefused((string) $response->state)) {
             $transaction->payment_status = 'refused';
             $transaction->save();
             Ajde_Log::log("iDeal payment refused with state " . (string) $response->state);
             return false;
         }
         Ajde_Log::log("iDeal payment callback called with state " . (string) $response->state . " but no status change for transaction " . $secret . " detected");
         return false;
     } else {
         Ajde_Log::log("Wedeal::updatePayment() failed because: " . $res['response']);
         return false;
     }
 }
示例#6
0
 public static function __bootstrap()
 {
     Ajde_Model::register('user');
     if (Ajde_User::getLoggedIn()) {
         return true;
     }
     $user = new UserModel();
     $user->verifyCookie();
     return true;
 }
 public function addJson()
 {
     Ajde_Model::register($this);
     $cart = new CartModel();
     $cart->loadCurrent();
     $entity = Ajde::app()->getRequest()->getPostParam('entity');
     $entity_id = Ajde::app()->getRequest()->getPostParam('entity_id');
     $qty = Ajde::app()->getRequest()->getPostParam('qty');
     $cart->addItem($entity, $entity_id, $qty);
     return array('success' => true);
 }
示例#8
0
 /**
  *
  * @return UserModel
  */
 protected function getLoggedInUser()
 {
     if (!isset($this->_user)) {
         foreach ($this->_registerUserModels as $model) {
             Ajde_Model::register($model);
         }
         $user = new UserModel();
         $this->_user = $user->getLoggedIn();
     }
     return $this->_user;
 }
示例#9
0
 public function beforeInvoke()
 {
     foreach ($this->_registerAclModels as $model) {
         Ajde_Model::register($model);
     }
     if (!in_array($this->getAction(), $this->_allowedActions) && $this->hasAccess() === false) {
         Ajde::app()->getRequest()->set('message', __('Please login to continue / No access'));
         Ajde::app()->getResponse()->dieOnCode(Ajde_Http_Response::RESPONSE_TYPE_UNAUTHORIZED);
     } else {
         return true;
     }
 }
 public function checkout()
 {
     Ajde_Model::register($this);
     // Get existing transaction
     $transaction = new TransactionModel();
     $session = new Ajde_Session('AC.Shop');
     $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'));
     $cart = new CartModel();
     $cart->loadCurrent();
     $this->getView()->assign('cart', $cart);
     $this->getView()->assign('user', $this->getLoggedInUser());
     $this->getView()->assign('transaction', $transaction);
     return $this->render();
 }
 function check()
 {
     // Register models
     Ajde_Model::register($this);
     // Ensure right view when coming from other action
     $this->setView(Ajde_View::fromRoute('browser/check'));
     // Get browsers
     $browsers = new BrowserCollection();
     $browsers->orderBy("sort");
     $browsers->load();
     // Set vars and return
     $this->getView()->assign("browsers", $browsers);
     return $this->render();
 }
 function view()
 {
     // Register models
     Ajde_Model::register('browser');
     // Menu colors
     $colors = array('html5' => 'f58220', 'wordpress' => '096aa5', 'drupal' => '009edc', 'typo3' => '3ab54a', 'joomla' => 'e52525');
     // Fast cycling browsers
     $fastCycle = array('chrome', 'firefox', 'opera');
     // Get browsers
     $browsers = new BrowserCollection();
     $browsers->orderBy("sort");
     $browsers->load();
     // Set vars and return
     $this->getView()->assign("browsers", $browsers);
     $this->getView()->assign("colors", $colors);
     $this->getView()->assign("fastCycle", $fastCycle);
     return $this->render();
 }
示例#13
0
 /**
  *
  * @return UserModel 
  */
 public function loadCurrent()
 {
     Ajde_Model::register('user');
     $loaded = false;
     if ($user = UserModel::getLoggedIn()) {
         // Do we have a saved cart for logged in user?
         if ($this->loadByUser($user) === false) {
             $this->user = $user->getPK();
             $this->insert();
         }
     } else {
         // Do we have a cart from IP address?
         if ($this->loadByClient() === false) {
             $this->client = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
             $this->insert();
         }
     }
     return true;
 }
示例#14
0
 public static function mergeUserToClient()
 {
     Ajde_Model::register('user');
     Ajde_Model::register('shop');
     if ($user = Ajde_User::getLoggedIn()) {
         // Do we have a saved cart for logged in user?
         $userCart = new CartModel();
         if ($userCart->loadByUser($user)) {
             // Do we have a saved cart for client?
             $clientCart = new CartModel();
             if ($clientCart->loadByClient() === false) {
                 $clientCart->client = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
                 $clientCart->insert();
             }
             foreach ($userCart->getItems() as $item) {
                 /* @var $item Ajde_Shop_Cart_Item */
                 $clientCart->addItem($item->getEntity(), null, $item->getQty());
             }
             $userCart->delete();
         }
     }
 }
示例#15
0
文件: SsoModel.php 项目: nabble/ajde
 public function __construct()
 {
     parent::__construct();
     $this->setEncryptedFields(['data']);
 }
示例#16
0
 /**
  *
  * @param string $entity
  * @return Ajde_Model
  */
 protected function _getEntityModel($entityName)
 {
     Ajde_Model::registerAll();
     $entityModelName = ucfirst((string) $entityName) . 'Model';
     return new $entityModelName();
 }
 public function browser()
 {
     Ajde_Model::register("browser");
     return $this->render();
 }
 function edit()
 {
     Ajde_Model::register($this);
     return $this->render();
 }
 public function commitJson()
 {
     $operation = Ajde::app()->getRequest()->getParam('operation');
     $crudId = Ajde::app()->getRequest()->getParam('crudId');
     $id = Ajde::app()->getRequest()->getPostParam('id', false);
     Ajde_Model::registerAll();
     switch ($operation) {
         case 'delete':
             return $this->delete($crudId, $id);
             break;
         case 'save':
             return $this->save($crudId, $id);
             break;
         case 'sort':
             return $this->sort($crudId, $id);
             break;
         default:
             return array('operation' => $operation, 'success' => false);
             break;
     }
 }
示例#20
0
文件: Revision.php 项目: nabble/ajde
 public function save()
 {
     // check all changed fields
     $modelName = get_class($this);
     $shadowModel = new $modelName();
     /* @var $shadowModel Ajde_Model */
     $shadowModel->loadByPK($this->getPK());
     if ($shadowModel->_hasMeta) {
         $shadowModel->populateMeta();
     }
     // old values
     $oldValues = $shadowModel->values();
     foreach ($oldValues as &$oldValue) {
         @($oldValue = (string) $oldValue);
     }
     // populate meta of current model, but don't override
     if ($this->_hasMeta) {
         $this->populateMeta(false, false);
     }
     // new values
     $newValues = $this->values();
     foreach ($newValues as $k => &$newValue) {
         if ($k == 'meta_4') {
             //                die('hier');
         }
         @($newValue = (string) $newValue);
     }
     // ignore fields
     foreach ($this->_ignoreFieldInRevision as $ignoreField) {
         unset($oldValues[$ignoreField]);
         unset($newValues[$ignoreField]);
     }
     // ignore fields
     foreach ($this->_ignoreFieldInRevisionIfEmpty as $ignoreField) {
         if (!isset($newValues[$ignoreField]) || empty($newValues[$ignoreField])) {
             unset($oldValues[$ignoreField]);
             unset($newValues[$ignoreField]);
         }
     }
     if ($diffs = array_diff_assoc($oldValues, $newValues)) {
         foreach ($diffs as $diffField => $diffValue) {
             $revision = new RevisionModel();
             $revision->model = $this->getModelName();
             $revision->foreignkey = $this->getPK();
             $revision->user = UserModel::getLoggedIn();
             $revision->field = $diffField;
             $revision->old = issetor($oldValues[$diffField]);
             $revision->new = issetor($newValues[$diffField]);
             $revision->insert();
         }
     }
     return parent::save();
 }
示例#21
0
 /**
  * @return MediatypeModel
  */
 public function getMediatype()
 {
     $this->loadParent('mediatype');
     return parent::getMediatype();
 }
示例#22
0
 public function __construct()
 {
     parent::__construct();
     $this->setEncryptedFields(['ip', 'name', 'email', 'shipment_address', 'shipment_zipcode', 'shipment_city', 'shipment_region', 'shipment_country', 'shipment_description', 'shipment_trackingcode', 'shipment_secret']);
 }
 public function paymentJson()
 {
     $request = Ajde::app()->getRequest();
     $provider = $request->getPostParam('provider', false);
     if (empty($provider)) {
         return array('success' => false, 'message' => __('Please choose a payment provider'));
     }
     // Check for current transaction
     Ajde_Model::register($this);
     $transaction = new TransactionModel();
     $session = new Ajde_Session('AC.Shop');
     if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) {
         if ($transaction->payment_status !== 'pending') {
             return array('success' => false, 'message' => __('Payment already initiated, please refresh this page'));
         }
     } else {
         return array('success' => false, 'message' => __('No current transaction found'));
     }
     $transaction->payment_provider = $provider;
     $provider = $transaction->getProvider();
     $redirectUrl = $provider->getRedirectUrl();
     if ($redirectUrl !== false) {
         $transaction->payment_status = 'requested';
         $transaction->save();
         $cart = new CartModel();
         $cart->loadCurrent();
         $cart->emptyItems();
         if ($provider->usePostProxy()) {
             $this->setAction('postproxy');
             $proxy = $this->getView();
             $proxy->assign('provider', $provider);
             return array('success' => true, 'postproxy' => $proxy->render());
         }
         return array('success' => true, 'redirect' => $redirectUrl);
     }
     return array('success' => false, 'message' => 'Could not contact the payment provider, please try again');
 }
示例#24
0
 public function updatePayment()
 {
     // PHP 4.1
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $header = '';
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30);
     // assign posted variables to local variables
     $item_name = $_POST['item_name'];
     $item_number = $_POST['item_number'];
     $payment_status = $_POST['payment_status'];
     $payment_amount = $_POST['mc_gross'];
     $payment_currency = $_POST['mc_currency'];
     $txn_id = $_POST['txn_id'];
     $receiver_email = $_POST['receiver_email'];
     $payer_email = $_POST['payer_email'];
     Ajde_Model::register('shop');
     $secret = $_POST['custom'];
     $transaction = new TransactionModel();
     if (!$transaction->loadByField('secret', $secret)) {
         Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
     }
     if (!$fp) {
         // HTTP ERROR
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, "VERIFIED") == 0) {
                 // check the payment_status is Completed
                 if ($payment_status == 'Completed') {
                     $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL;
                     $transaction->payment_details = $details;
                     $transaction->payment_status = 'completed';
                     $transaction->save();
                 } else {
                     $transaction->payment_status = 'refused';
                     $transaction->save();
                     Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                 }
                 // check that txn_id has not been previously processed
                 // check that receiver_email is your Primary PayPal email
                 // check that payment_amount/payment_currency are correct
                 // process payment
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     // log for manual investigation
                     $transaction->payment_status = 'refused';
                     $transaction->save();
                     Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id);
                 }
             }
         }
         fclose($fp);
     }
 }
示例#25
0
 /**
  * @param Ajde_Model|Ajde_Collection $object
  */
 public function touchCache($object = null)
 {
     Ajde_Cache::getInstance()->updateHash(isset($object) ? $object->hash() : time());
 }
示例#26
0
文件: MetaModel.php 项目: nabble/ajde
 public function reset()
 {
     $this->_metaValues = [];
     $this->_options = [];
     parent::reset();
 }
示例#27
0
文件: FormModel.php 项目: nabble/ajde
 /**
  * @return MetaModel
  */
 public function getEmailTo()
 {
     $this->loadParent('email_to');
     return parent::get('email_to');
 }
示例#28
0
 public function getFromEmail()
 {
     return parent::hasNotEmpty('from_email') ? parent::get('from_email') : config('app.email');
 }
示例#29
0
 protected function _load($sql, $values, $populate = true)
 {
     $return = parent::_load($sql, $values, $populate);
     if ($return && Ajde::app()->hasRequest() && Ajde::app()->getRequest()->getParam('filterPublished', false) == true) {
         $this->filterPublished();
     }
     return $return;
 }
示例#30
0
文件: Model.php 项目: nabble/ajde
 protected function _load($sql, $values, $populate = true)
 {
     $return = parent::_load($sql, $values, $populate);
     if (Ajde_Lang::getInstance()->autoTranslateModels() && $return) {
         // get translation
         $lang = Ajde_Lang::getInstance();
         if ($translation = $this->getTranslated($lang->getLang())) {
             /* @var $translation Ajde_Lang_Proxy_Model */
             $this->reset();
             $this->loadFromValues($translation->values());
         }
     }
     return $return;
 }