public function searchJson() { $q = Ajde::app()->getRequest()->getParam('query'); $collection = new NodeCollection(); // split search terms $terms = explode(' ', $q); // search on node fields $searchGroup = new Ajde_Filter_WhereGroup(Ajde_Query::OP_OR); foreach ($terms as $term) { $termGroup = $collection->getTextFilterGroup($term, Ajde_Query::OP_OR); if ($termGroup !== false) { $searchGroup->addFilter($termGroup); } } $collection->addFilter($searchGroup); // search on meta search $collection->addFilter(new Ajde_Filter_LeftJoin('node_meta', 'node_meta.node', 'node.id')); $searchGroup = new Ajde_Filter_WhereGroup(Ajde_Query::OP_OR); foreach ($terms as $term) { $searchGroup->addFilter(new Ajde_Filter_Where('node_meta.value', Ajde_Filter::FILTER_LIKE, '%' . $term . '%', Ajde_Query::OP_OR)); } $collection->addFilter($searchGroup); $collection->getQuery()->addGroupBy('node.id'); // join in nodetype info $collection->joinNodetype(); $collection->getQuery()->addSelect('nodetype.name AS nodetype_name'); $collection->getQuery()->addSelect('nodetype.icon AS nodetype_icon'); $suggestions = []; foreach ($collection as $node) { /* @var $node NodeModel */ $suggestions[] = ['value' => "<i class='" . $node->get('nodetype_icon') . "'></i> " . $node->displayField(), 'data' => $node->getPK()]; } return ['query' => $q, 'suggestions' => $suggestions]; }
public function load() { if (Ajde::app()->getRequest()->getParam('filterPublished', false) == true) { $this->filterPublished(); } return parent::load(); }
public function settings() { Ajde::app()->getDocument()->setTitle('Setup settings'); $decorator = new Ajde_Crud_Cms_Meta_Decorator(); $this->getView()->assign('decorator', $decorator); return $this->render(); }
function view() { // Grab the view to easily assign variables $view = $this->getView(); // Get all warnings from Ajde_Dump::warn() if (Ajde_Dump::getWarnings()) { $view->assign('warn', Ajde_Dump::getWarnings()); } // Get all dumps from Ajde_Dump::dump() [Aliased as a global function dump()] if (Ajde_Dump::getAll()) { $view->assign('dump', Ajde_Dump::getAll()); } // Get request parameters $view->assign('request', Ajde::app()->getRequest()); // Get Configuration stage $view->assign('configstage', Config::$stage); // Get database queries if (Ajde_Core_Autoloader::exists('Ajde_Db_PDO')) { $view->assign('database', Ajde_Db_PDO::getLog()); } // Get language $view->assign('lang', Ajde_Lang::getInstance()->getLang()); // Get session $view->assign('session', $_SESSION); // Get ACL if (Ajde_Core_Autoloader::exists('Ajde_Acl')) { $view->assign('acl', Ajde_Acl::getLog()); } // Get the application timer Ajde::app()->endTimer(0); Ajde::app()->endTimer(Ajde::app()->getLastTimerKey()); $view->assign('timers', Ajde::app()->getTimers()); return $this->render(); }
public function isAuthenticated() { if (Ajde::app()->getRequest()->getParam('error_code', false)) { return false; } return true; }
public function __construct($route) { // See if first part is language code (i.e. first part is exactly // two characters in length) if (strlen($route) === 2 || substr($route, 2, 1) === '/') { $shortLang = substr($route, 0, 2); $langInstance = Ajde_Lang::getInstance(); if ($lang = $langInstance->getAvailableLang($shortLang)) { $this->set("lang", $lang); $route = substr($route, 3); } } if (!$route) { $route = Config::get('homepageRoute'); } // Check for route aliases $aliases = Config::get("aliases"); if (array_key_exists($route, $aliases)) { $this->_route = $aliases[$route]; } else { $this->_route = $route; } // Get route parts $routeParts = $this->_extractRouteParts(); if (empty($routeParts)) { $exception = new Ajde_Exception(sprintf("Invalid route: %s", $route), 90021); Ajde::routingError($exception); } $defaultParts = Config::get('defaultRouteParts'); $parts = array_merge($defaultParts, $routeParts); foreach ($parts as $part => $value) { $this->set($part, $value); } }
private static function _getFileInfo($base, $action, $format = 'html') { // go see what templates are available $dirPrefixPatterns = [APP_DIR, CORE_DIR]; $fileNamePatterns = [$action . '.' . $format, $action]; $fileTypes = ['phtml' => 'Phtml', 'xhtml' => 'Xhtml']; foreach ($dirPrefixPatterns as $dirPrefixPattern) { $prefixedBase = $dirPrefixPattern . $base; foreach ($fileNamePatterns as $fileNamePattern) { foreach ($fileTypes as $fileType => $parserType) { $filePattern = $fileNamePattern . '.' . $fileType; if (!substr_count($prefixedBase, DIRECTORY_SEPARATOR . 'layout' . DIRECTORY_SEPARATOR)) { $layoutDir = 'layout.' . Ajde::app()->getDocument()->getLayout()->getName() . DIRECTORY_SEPARATOR; if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase . TEMPLATE_DIR . $layoutDir, $filePattern)) { return ['filename' => $fileMatch, 'parser' => $parserType]; } } if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase . TEMPLATE_DIR, $filePattern)) { return ['filename' => $fileMatch, 'parser' => $parserType]; } } } } return false; }
/** * * @return Ajde_Document */ public function getDocument() { if ($this->getParser()->getTemplate()->has('document')) { return $this->getParser()->getTemplate()->getDocument(); } else { return Ajde::app()->getDocument(); } }
public function setupExternalPageCache() { if (!UserModel::getLoggedIn() && Ajde::app()->getRequest()->method() === 'get' && config('layout.cache.externalPageCache')) { $this->setCacheControl(self::CACHE_CONTROL_PUBLIC); $this->setMaxAge(1 / 24); // 1 hour } }
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('shop.transaction.wedeal.callbackUsername')) { Ajde_Log::log('Invalid username for callback of transaction ' . $secret); return false; } if ($password != config('shop.transaction.wedeal.callbackPassword')) { Ajde_Log::log('Invalid password for callback of transaction ' . $secret); return false; } $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 = ['type' => 'query', 'merchant' => ['username' => config('shop.transaction.wedeal.username'), 'password' => config('shop.transaction.wedeal.password'), 'reference' => $secret]]; // Pause a little before request is made to allow for processing on provider // as this request will be made synchronously after payment sleep(3); $res = $this->sendRequest($request); if ($res['success'] === true) { $response = $res['response']->paymentinfo; $count = (int) $res['response']->count; // get transaction details if ($count == 0) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('iDeal callback didn\'t return any transaction for ' . $secret); } elseif (self::isPaid((string) $response->state)) { if ((string) $response->id != $id) { Ajde_Log::log('IDs don\'t match for iDeal callback of transaction ' . $secret); } else { $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 ['success' => true, 'transaction' => $transaction]; } } elseif (self::isRefused((string) $response->state)) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('iDeal payment refused with state ' . (string) $response->state); } else { Ajde_Log::log('iDeal payment callback called with state ' . (string) $response->state . ' but no status change for transaction ' . $secret . ' detected'); } } else { Ajde_Log::log('Wedeal::updatePayment() failed because: ' . $res['response']); } return ['success' => false, 'transaction' => $transaction]; }
function nocookies() { // set a cookie so a user can change settings in browsers which only // gives users the choice to enable cookies when a website tries to set one $session = new Ajde_Session('_ajde'); $returnto = Ajde::app()->getRequest()->getParam('returnto', ''); $this->getView()->assign('returnto', $returnto); die($this->render()); }
public function beforeInvoke() { if ($this->hasAccess()) { return true; } else { Ajde::app()->getRequest()->set('message', trans('Please log on to view this page')); Ajde::app()->getResponse()->dieOnCode(Ajde_Http_Response::RESPONSE_TYPE_UNAUTHORIZED); } }
function afterInvoke() { $title = __('Widget'); if (Ajde::app()->getDocument()->hasTitle()) { $title = $title . '/' . Ajde::app()->getDocument()->getTitle(); } Ajde::app()->getDocument()->setTitle($title); return true; }
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; } }
public function addJson() { $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 ['success' => true]; }
protected function hasAccess() { if (!isset($this->_hasAccess)) { $conditions = $this->getAclConditions(); $aclTimer = Ajde::app()->addTimer('<i>ACL validation for ' . implode('/', $conditions) . '</i>'); $this->_hasAccess = $this->validateAccess($conditions); Ajde::app()->endTimer($aclTimer); } return $this->_hasAccess; }
public function load() { parent::load(); if ($this->count()) { $aclTimer = Ajde::app()->addTimer('<i>ACL validation for collection</i>'); $this->validateModels(); Ajde::app()->endTimer($aclTimer); } return $this->_items; }
public static function getLinkTemplateFilename($type, $format = 'null') { if (Ajde::app()->getDocument()->hasLayout()) { $layout = Ajde::app()->getDocument()->getLayout(); } else { $layout = new Ajde_Layout(Config::get("layout")); } $format = issetor($format, 'html'); return LAYOUT_DIR . $layout->getName() . '/link/' . $type . '.' . $format . '.php'; }
/** * * @param Ajde_Core_Route $route * @return Ajde_Document */ public static function fromRoute(Ajde_Core_Route $route) { $format = $route->getFormat(); $documentClass = "Ajde_Document_Format_" . ucfirst($format); if (!Ajde_Core_Autoloader::exists($documentClass)) { $exception = new Ajde_Exception("Document format {$format} not found", 90009); Ajde::routingError($exception); } return new $documentClass(); }
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); }
public function __construct($name, $style = 'default', $format = null) { $this->setName($name); $this->setStyle($style); $base = LAYOUT_DIR . $this->getName() . '/'; $action = $this->getStyle(); if (!$format) { $format = Ajde_Http_Request::isAjax() && $this->exist($base, $action, 'ajax') || Ajde::app()->getDocument()->getFormat() === 'ajax' ? 'ajax' : 'html'; } parent::__construct($base, $action, $format); }
public function render() { Ajde::app()->getDocument()->setLayout(new Ajde_Layout('empty')); Ajde::app()->getResponse()->removeHeader('Set-Cookie'); if (Ajde::app()->getRequest()->getRoute()->getAction() == 'resourceCompressed') { $this->registerDocumentProcessor('css', 'compressor'); } else { $this->registerDocumentProcessor('css'); } return parent::render(); }
public function displayLang() { Ajde::app()->getDocument()->getLayout()->getParser()->getHelper()->requireCssPublic('core/flags.css'); $lang = Ajde_Lang::getInstance(); $currentLang = $this->get('lang'); if ($currentLang) { $image = '<img src="" class="flag flag-' . strtolower(substr($currentLang, 3, 2)) . '" alt="' . $currentLang . '" />'; return $image . $lang->getNiceName($currentLang); } return ''; }
public function resetJson() { $user = new UserModel(); $id = Ajde::app()->getRequest()->getPostParam('id'); $return = [false]; if (false !== $user->loadByPK($id)) { $hash = $user->resetUser(); $return = ['success' => $hash !== false]; } else { $return = ['success' => false]; } return $return; }
public function __construct($base, $action, $format = 'html') { $this->setBase($base); $this->setAction($action); $this->setFormat($format); if (($fileInfo = $this->getFileInfo()) === false) { $exception = new Ajde_Exception(sprintf("Template file in %s,\n\t\t\t\t\tfor action %s with format %s not found", $base, $action, $format), 90010); Ajde::routingError($exception); } $className = 'Ajde_Template_Parser_' . $fileInfo['parser']; $parser = new $className($this); $this->setFilename($fileInfo['filename']); $this->setParser($parser); }
public function view() { Ajde_Model::register($this); // Direct object creation and chaining only from PHP 5.3! // Use $blog = new BlogCollection() instead /* @var $samples SamplesCollection */ $samples = SamplesCollection::create()->orderBy('sort', Ajde_Query::ORDER_ASC)->filter('published', 1); if ($this->hasId()) { $samples->addFilter(new Ajde_Filter_Where('id', Ajde_Filter::FILTER_EQUALS, $this->getId())); } $this->getView()->assign('samples', $samples); Ajde_Dump::warn('This is a test warning'); Ajde::app()->getDocument()->setDescription("This is the samples module"); return $this->render(); }
public function typeBtnJson() { $value = Ajde::app()->getRequest()->getPostParam('type'); $id = Ajde::app()->getRequest()->getPostParam('id', false); $model = new MediaModel(); if (!is_array($id)) { $id = [$id]; } foreach ($id as $elm) { $model->loadByPK($elm); $model->set('mediatype', $value); $model->save(); } return ['success' => true, 'message' => Ajde_Component_String::makePlural(count($id), 'media') . ' changed']; }
public function disconnect() { $returnto = Ajde::app()->getRequest()->getParam('returnto', ''); if ($user = $this->getLoggedInUser()) { // should always be true, since we are inside a Ajde_User_Controller $sso = new SsoModel(); if ($sso->loadByFields(['user' => $user->getPK(), 'provider' => $this->_providername])) { $this->_provider->destroySession(); $sso->delete(); Ajde_Session_Flash::alert('Disconnected from ' . ucfirst($this->_providername)); $this->redirect($returnto); } else { Ajde_Session_Flash::alert('Could not disconnect from ' . ucfirst($this->_providername)); $this->redirect($returnto); } } }
public static function getLinkTemplateFilename($type, $format = 'null') { if (Ajde::app()->getDocument()->hasLayout()) { $layout = Ajde::app()->getDocument()->getLayout(); } else { $layout = new Ajde_Layout(config('layout.frontend')); } $format = issetor($format, 'html'); $dirPrefixPatterns = [APP_DIR, CORE_DIR]; foreach ($dirPrefixPatterns as $dirPrefixPattern) { $prefixedLayout = $dirPrefixPattern . LAYOUT_DIR; if (self::exist($prefixedLayout . $layout->getName() . '/link/' . $type . '.' . $format . '.php')) { return $prefixedLayout . $layout->getName() . '/link/' . $type . '.' . $format . '.php'; } } return false; }
public function markPaidJson() { $id = Ajde::app()->getRequest()->getPostParam('id', false); $transaction = new TransactionModel(); if (!is_array($id)) { $id = [$id]; } $c = 0; foreach ($id as $elm) { $transaction->loadByPK($elm); if ($transaction->payment_status !== 'completed') { $transaction->paid(); $c++; } } return ['success' => true, 'message' => Ajde_Component_String::makePlural($c, 'transaction') . ' marked as paid']; }