/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { I18n::instance()->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { I18n::instance()->lang($this->cookies->get('lang')->getValue()); } // Send i18n, auth and langs to the view $this->view->setVars(array('auth' => Auth::instance(), 'i18n' => I18n::instance(), 'siteLangs' => array_map('__', $this->config->i18n->langs->toArray()))); }
/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { I18n::instance()->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { I18n::instance()->lang($this->cookies->get('lang')->getValue()); } $this->las = \Las\Library\Arr::from_model(Settings::find(array('status = ' . Settings::ACTIVE)), 'category', array('name' => 'value')); // Send i18n, auth and langs to the view $this->view->setVars(array('auth' => Auth::instance(), 'i18n' => I18n::instance(), 'siteLangs' => array_map('__', $this->config->i18n->langs->toArray()), 'las' => $this->las)); }
/** * Render views from volt files * * @package las * @version 1.0 */ public function voltAction() { $this->view->setVars(array('i18n' => I18n::instance(), 'auth' => Auth::instance())); ob_start(); $e = ''; foreach (array('frontend', 'backend', 'cli', 'documentation') as $module) { foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_PATH . '/app/' . $module . '/views/', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) { if (!$item->isDir() && $item->getExtension() == 'volt') { $this->view->setViewsDir(ROOT_PATH . '/app/' . $module . '/views/'); $subPath = $iterator->getSubPathName(); $file = strstr($item->getFilename(), '.volt', true); $dir = strstr($subPath, $item->getFilename(), true); $e .= $this->view->partial($dir . $file); } } } ob_get_clean(); //\Las\Console::log($e); }
/** * New payment Action * * @package las * @version 1.0 */ public function newAction() { $params = $this->router->getParams(); if (Auth::instance()->logged_in() && isset($params[0]) && ($adapter = $params[0])) { if ($checkout = $this->session->get('checkout')) { switch ($adapter) { case 'dotpay': $this->view->setVar('adapter', $this->tag->linkTo(array('http://www.dotpay.pl', $this->tag->image(array('img/dotpay.png', 'alt' => 'dotpay')), 'target' => '_blank', 'local' => false))); break; default: $this->view->setVar('adapter', $this->tag->linkTo(array('http://www.paypal.com', $this->tag->image(array('img/paypal.png', 'alt' => 'dotpay')), 'target' => '_blank', 'local' => false))); break; } if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $payment = new Payments(); $payment = $payment->add($checkout); // Check if new payment was valid and added if ($payment instanceof \Las\Models\Payments) { // Switch to payment adapter switch ($adapter) { case 'dotpay': $dotpay = Payment::instance('dotpay'); $fields = array('currency' => 'USD', 'amount' => number_format($payment->total, 2, '.', ''), 'lang' => substr(I18n::instance()->lang(), 0, 2), 'description' => __('Chocolate') . ' ' . $this->config->app->name, 'control' => $payment->control, 'type' => 3, 'buttontext' => __('Back to site'), 'email' => $payment->email, 'firstname' => $payment->firstname, 'lastname' => $payment->lastname); $this->view->pick('msg'); $this->tag->setTitle(__('Redirect')); $this->view->setVar('title', __('Redirect')); $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Notice') . '!</strong> ' . __("Redirecting to dotpay")); $this->view->setVar('content', $dotpay->process($fields)); break; default: $paypal = Payment::instance('paypal'); $fields = array('AMT' => $payment->total, 'CURRENCYCODE' => 'USD', 'LOCALECODE' => substr(I18n::instance()->lang(), 0, 2), 'NOSHIPPING' => '1', 'HDRIMG' => $this->url->getStatic('img/logo.png'), 'EMAIL' => $this->config->app->admin, 'ALLOWNOTE' => '0', 'PAYMENTREQUEST_0_AMT' => $payment->total, 'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', 'PAYMENTREQUEST_0_DESC' => $this->config->app->name, 'L_PAYMENTREQUEST_0_NAME0' => __('Chocolate') . ' ' . $this->config->app->name, 'L_PAYMENTREQUEST_0_AMT0' => $payment->amount, 'L_PAYMENTREQUEST_0_QTY0' => $payment->quantity); $paypal->process($fields); // Check that the response from the Paypal server is ok. if ($paypal->get('ACK') === 'Success') { // Store token in SESSION $this->session->set('paypal_token_' . $paypal->get('TOKEN'), $fields['AMT']); // We now send the user to the Paypal site for them to provide their details $fields['token'] = $paypal->get('TOKEN'); unset($fields['PAYMENTACTION']); $payment->control = $fields['token']; $payment->date_update = date('Y-m-d H:i:s'); $payment->response = json_encode($paypal->get()); $payment->save(); $url = $paypal->redirectURL('express-checkout', $fields); $this->response->redirect($url, true); } break; } } else { $this->view->setVar('errors', $payment); $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } } } else { $this->response->redirect('order'); } } else { $this->response->redirect('user/signin'); } }
/** * Catch the exception and log it, display pretty view * * @package las * @version 1.0 * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output echo Dump::all($errors); } else { // Display pretty view of the error $di = new \Phalcon\DI\FactoryDefault(); $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->setViewsDir(ROOT_PATH . '/app/frontend/views/'); $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di)); echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config)); // Log errors to file and send email with errors to admin \Las\Bootstrap::log($errors); } }
/** * Translate message * * @package las * @version 1.0 * * @param string $string string to translate * @param array $values replace substrings * * @return string translated string */ function __($string, array $values = NULL) { return \Las\Library\I18n::instance()->_($string, $values); }