示例#1
0
 /**
  * @return UserModel
  */
 protected function getLoggedInUser()
 {
     if (!isset($this->_user)) {
         $this->_user = UserModel::getLoggedIn();
     }
     return $this->_user;
 }
示例#2
0
 public function uploadJson()
 {
     $filename = Ajde::app()->getRequest()->getPostParam('filename', false, Ajde_Http_Request::TYPE_HTML);
     if (!$filename) {
         return ['success' => false];
     }
     $mediatype = Ajde::app()->getRequest()->getPostParam('mediatype', false);
     $name = Ajde::app()->getRequest()->getPostParam('name', false);
     $oauthToken = Ajde::app()->getRequest()->getPostParam('oauthToken', false);
     $media = new MediaModel();
     $media->mediatype = $mediatype;
     $media->pointer = $filename;
     // see if we can save a file from Google Drive
     $driveResult = $media->saveFileFromDrive($name, $oauthToken);
     if ($driveResult === true) {
         $extension = pathinfo($media->pointer, PATHINFO_EXTENSION);
     } else {
         if ($driveResult === 'error') {
             return ['success' => false];
         } else {
             $extension = pathinfo($filename, PATHINFO_EXTENSION);
             $title = pathinfo($filename, PATHINFO_FILENAME);
             $media->name = $title;
             $media->thumbnail = $filename;
         }
     }
     if (in_array(strtolower($extension), $this->_imageExtensions)) {
         $media->type = 'image';
     } else {
         $media->type = 'file';
     }
     $media->user = UserModel::getLoggedIn()->getPK();
     return ['success' => $media->insert()];
 }
示例#3
0
文件: Html.php 项目: nabble/ajde
 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 setup()
 {
     Ajde_Model::register($this);
     Ajde_Model::register('user');
     // Get existing transaction / user details
     $transaction = new TransactionModel();
     $session = new Ajde_Session('AC.Shop');
     $user = UserModel::getLoggedIn();
     if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) {
         $name = $transaction->name;
         $email = $transaction->email;
         $address = $transaction->shipment_address;
         $zipcode = $transaction->shipment_zipcode;
         $city = $transaction->shipment_city;
         $region = $transaction->shipment_region;
         $country = $transaction->shipment_country;
         $comment = $transaction->comment;
     } elseif ($user !== false) {
         // Insert intermediate transaction to save country and present user
         // with shipping options, ignore response
         $this->setupJson($user);
         $name = $user->fullname;
         $email = $user->email;
         $address = $user->address;
         $zipcode = $user->zipcode;
         $city = $user->city;
         $region = $user->region;
         $country = $user->country;
         $comment = '';
     } else {
         // Insert intermediate transaction to save cart and allow user to
         // see shipping options when country is choosen
         $this->setupJson(true);
         $name = '';
         $email = '';
         $address = '';
         $zipcode = '';
         $city = '';
         $region = '';
         $country = '';
         $comment = '';
     }
     $view = $this->getView();
     $view->assign('name', $name);
     $view->assign('email', $email);
     $view->assign('address', $address);
     $view->assign('zipcode', $zipcode);
     $view->assign('city', $city);
     $view->assign('region', $region);
     $view->assign('country', $country);
     $view->assign('comment', $comment);
     $view->assign('user', $user);
     return $this->render();
 }
示例#5
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;
 }
示例#6
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();
 }
示例#7
0
 public function quickJson()
 {
     $parent = Ajde::app()->getRequest()->getPostParam('parent');
     $title = Ajde::app()->getRequest()->getPostParam('title');
     $due = Ajde::app()->getRequest()->getPostParam('due');
     $allocated = Ajde::app()->getRequest()->getPostParam('allocated');
     $model = new NodeModel();
     $model->populate(['parent' => $parent, 'title' => $title, 'user' => UserModel::getLoggedIn()->getPK(), 'nodetype' => NodeModel::NODETYPE_ISSUE]);
     Ajde_Event::trigger($model, 'beforeCrudSave', []);
     $success = $model->insert();
     Ajde_Event::trigger($model, 'afterCrudSave', []);
     $model->saveMetaValue(NodeModel::META_ISSUESTATUS, NodeModel::ISSUESTATUS_NEW);
     $model->saveMetaValue(NodeModel::META_ISSUEDUE, $due);
     $model->saveMetaValue(NodeModel::META_ALLOCATED, $allocated);
     return ['success' => $success, 'message' => $success ? 'Node added' : 'Something went wrong'];
 }
示例#8
0
 public function item()
 {
     // we want to display published nodes only
     if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
         Ajde::app()->getRequest()->set('filterPublished', true);
     }
     // get the current slug
     $slug = $this->getSlug();
     /* @var $product ProductModel */
     $product = new ProductModel();
     $product->loadBySlug($slug);
     $this->product = $product;
     if ($product->getPublished() === false) {
         Ajde_Dump::warn('Previewing unpublished product');
     }
     // check if we have a hit
     if (!$product->hasLoaded()) {
         Ajde::app()->getResponse()->redirectNotFound();
     }
     Ajde_Event::trigger($this, 'onAfterProductLoaded', [$product]);
     // update cache
     Ajde_Cache::getInstance()->updateHash($product->hash());
     Ajde_Cache::getInstance()->addLastModified(strtotime($product->updated));
     // set title
     if (!Ajde::app()->getDocument()->hasNotEmpty('title')) {
         Ajde::app()->getDocument()->setTitle($product->getTitle());
     }
     // set summary
     if ($product->content) {
         Ajde::app()->getDocument()->setDescription(Ajde_Component_String::trim(strip_tags($product->content), '100'));
     }
     // set author
     $product->loadParent('user');
     /** @var UserModel $owner */
     $owner = $product->getUser();
     Ajde::app()->getDocument()->setAuthor($owner->getFullname());
     // featured image
     if ($image = $product->featuredImage()) {
         Ajde::app()->getDocument()->setFeaturedImage($image);
     }
     // pass node to view
     $this->setAction('item');
     $this->getView()->assign('product', $product);
     // render the template
     return $this->render();
 }
示例#9
0
文件: Cart.php 项目: nabble/ajde
 /**
  * @return UserModel
  */
 public function loadCurrent()
 {
     $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;
 }
示例#10
0
 public function beforeInvoke($allowed = [])
 {
     $token = Ajde::app()->getRequest()->getParam('token', false);
     if ($token) {
         $user = new UserModel();
         list($uid, $hash) = explode(':', $token);
         if ($user->loadByPK($uid)) {
             if ($user->getCookieHash(false) === $hash) {
                 $user->login();
             }
         }
     }
     $user = UserModel::getLoggedIn();
     if ($user) {
         return parent::beforeInvoke($allowed);
     }
     Ajde::app()->getRequest()->set('message', trans('You may not have the required permission to view this page'));
     Ajde::app()->getResponse()->dieOnCode(Ajde_Http_Response::RESPONSE_TYPE_UNAUTHORIZED);
 }
示例#11
0
 public static function getNodeOptions()
 {
     // show only
     $showOnlyWhenFields = ['title', 'subtitle', 'content', 'summary', 'media', 'tag', 'additional_media', 'children', 'published', 'related_nodes'];
     $showOnlyWhen = [];
     $nodetypes = new NodetypeCollection();
     foreach ($nodetypes as $nodetype) {
         foreach ($showOnlyWhenFields as $field) {
             if (!isset($showOnlyWhen[$field])) {
                 $showOnlyWhen[$field] = [];
             }
             if ($nodetype->get($field) == 1) {
                 $showOnlyWhen[$field][] = $nodetype->getPK();
             }
         }
     }
     $options = new Ajde_Crud_Options();
     $options->selectFields()->selectField('slug')->setHelp('Changing the slug might impact SEO scores and break existing internal links')->up()->selectField('nodetype')->setOrderBy('sort')->setIsRequired(false)->up()->selectField('title')->addShowOnlyWhen('nodetype', $showOnlyWhen['title'])->setFunction('displayTreeName')->setEmphasis(true)->up()->selectField('subtitle')->addShowOnlyWhen('nodetype', $showOnlyWhen['subtitle'])->up()->selectField('content')->addShowOnlyWhen('nodetype', $showOnlyWhen['content'])->up()->selectField('summary')->addShowOnlyWhen('nodetype', $showOnlyWhen['summary'])->setDisableRichText(true)->up()->selectField('media')->addShowOnlyWhen('nodetype', $showOnlyWhen['media'])->setShowLabel(false)->setUsePopupSelector(true)->setListRoute('admin/media:view.crud')->setUseImage(true)->addTableFileField('thumbnail', UPLOAD_DIR)->setThumbDim(300, 300)->up()->selectField('tag')->addShowOnlyWhen('nodetype', $showOnlyWhen['tag'])->setType('multiple')->setEditRoute('admin/tag:view.crud')->setThumbDim(30, 30)->setShowLabel(false)->setCrossReferenceTable('node_tag')->setSimpleSelector(true)->up()->selectField('parent')->addShowOnlyWhen('nodetype', $showOnlyWhen['children'])->setType('fk')->setModelName('node')->setShowLabel(true)->setUsePopupSelector(true)->setListRouteFunction('listRouteParent')->up()->selectField('published')->addShowOnlyWhen('nodetype', $showOnlyWhen['published'])->setFunction('displayPublished')->setType('boolean')->up()->selectField('published_start')->addShowOnlyWhen('nodetype', $showOnlyWhen['published'])->up()->selectField('published_end')->addShowOnlyWhen('nodetype', $showOnlyWhen['published'])->up()->selectField('sort')->setType('sort')->up()->selectField('additional_media')->addShowOnlyWhen('nodetype', $showOnlyWhen['additional_media'])->setType('multiple')->setEditRoute('admin/media:view.crud')->addTableFileField('thumbnail', UPLOAD_DIR)->setHideMainColumn(true)->setUsePopupSelector(true)->setListRoute('admin/media:view.crud')->setModelName('media')->setThumbDim(100, 100)->addSortField('sort')->setShowLabel(false)->setCrossReferenceTable('node_media')->up()->selectField('children')->addShowOnlyWhen('nodetype', $showOnlyWhen['children'])->setModelName('node')->setParent('parent')->setHideInIframe(true)->setType('multiple')->setEditRouteFunction('editRouteChild')->addTableField('nodetype')->addSortField('sort')->setShowLabel(false)->up()->selectField('related_nodes')->addShowOnlyWhen('nodetype', $showOnlyWhen['related_nodes'])->setType('multiple')->setEditRoute('admin/node:view.crud')->setUsePopupSelector(true)->setListRoute('admin/node:view.crud')->setModelName('node')->setSimpleSelector(true)->addSortField('sort')->setShowLabel(false)->setChildField('related')->setCrossReferenceTable('node_related')->up()->selectField('added')->setIsReadonly(true)->up()->selectField('updated')->setFunction('displayAgo')->setIsReadonly(true)->up()->selectField('lang')->setFunction('displayLang')->setType('i18n')->setCloneFields(['nodetype', 'media'])->up()->up()->selectList()->selectButtons()->setNew(true)->setEdit(true)->setView(true)->setViewUrlFunction('getSlug')->addItemButton('child', 'addChildButton', 'btn-success add-child', false, true)->up()->setMain('title')->setShow(['title', 'lang', 'updated', 'published', 'sort'])->setThumbDim(50, 50)->setSearch(true)->selectView()->setMainFilter('nodetype')->setMainFilterGrouper('category')->setOrderBy('sort')->up()->up()->selectEdit()->selectLayout()->addRow()->addColumn()->setSpan(8)->addBlock()->setShow(['title', 'subtitle', 'content', 'summary'])->up()->addBlock()->setClass('meta')->up()->addBlock()->setClass('')->setTitle('Child nodes')->setShow(['children'])->up()->up()->addColumn()->setSpan(4)->addBlock()->setTitle('Featured image')->setClass('sidebar')->setShow(['media'])->up()->addBlock()->setTitle('Tags')->setClass('sidebar')->setShow(['tag'])->up()->addBlock()->setClass('sidebar')->setTitle('Additional media')->setShow(['additional_media'])->up()->addBlock()->setClass('sidebar')->setTitle('Related nodes')->setShow(['related_nodes'])->up()->addBlock()->setTitle('Node status')->setClass('well left')->setShow(['slug', 'published', 'published_start', 'published_end'])->up()->addBlock()->setTitle('Metadata')->setClass('well left')->setShow(['added', 'updated', 'parent', 'user', 'lang'])->finished();
     /* @var $decorator Ajde_Crud_Cms_Meta_Decorator */
     $decorator = new Ajde_Crud_Cms_Meta_Decorator();
     $decorator->setActiveBlock(1);
     $decorator->setOptions($options);
     $decorator->decorateInputs('nodetype_meta', 'nodetype', 'sort', 'nodetype', [new Ajde_Filter_Where('target', Ajde_Filter::FILTER_EQUALS, 'node')]);
     if (Ajde::app()->getRequest()->has('new')) {
         // set owner
         $user = UserModel::getLoggedIn();
         $options->selectFields()->selectField('user')->setValue($user->getPK())->finished();
         $options->selectFields()->selectField('slug')->setIsReadonly(true)->finished();
         if (!UserModel::isAdmin()) {
             $currentUser = UserModel::getLoggedIn();
             $subquery = '(SELECT user_node.user FROM user_node WHERE user_node.node IN (SELECT user_node.node FROM user_node WHERE user_node.user = '******' GROUP BY user_node.node))';
             $userFilters = [new Ajde_Filter_Where('user.id', Ajde_Filter::FILTER_IN, new Ajde_Db_Function($subquery))];
             $options->selectFields()->selectField('user')->setAdvancedFilter($userFilters);
         }
     }
     if (Ajde::app()->getRequest()->has('edit')) {
         if (!UserModel::isAdmin()) {
             $options->selectFields()->selectField('user')->setIsReadonly(true)->setUsePopupSelector(true)->finished();
         }
     }
     return $options;
 }
示例#12
0
 public static final function isInactive()
 {
     return !UserModel::getLoggedIn() && ($user = UserModel::getLastUser()) && self::getCookieValues('status') == 0;
 }