示例#1
0
 public function update()
 {
     $orderEntity = false;
     if ($this->isPost()) {
         $tableName = zbase_entity('custom_orders')->getTable();
         $name = zbase_request_input('name', false);
         $orderId = zbase_request_input('order_id', false);
         $amount = zbase_request_input('amount', false);
         $validators = ['name' => 'required', 'amount' => 'required', 'order_id' => 'required|exists:' . $tableName . ',order_id,name,' . $name . ',total,' . number_format($amount, 2) . ',status,1', 'date' => 'required|date_format:Y-m-d|before:' . zbase_date_now()->addDay(), 'payment_center' => 'required', 'file' => 'required|image'];
         $messages = ['order_id.exists' => 'Order ID, Name and Amount don\'t match.', 'amount.required' => 'Enter the amount that you deposited or paid.', 'file.required' => 'Kindly upload your deposit or payment slip.', 'file.image' => 'The file you uploaded is not an image.'];
         $this->validate(zbase_request(), $validators, $messages);
         $folder = zbase_storage_path() . '/zivsluck/order/receipts/';
         $newFilename = zbase_file_name_from_file($_FILES['file']['name'], $orderId, true);
         $newFilename = zbase_file_upload_image('file', $folder, $newFilename, 'png', [280, null]);
         if (file_exists($newFilename)) {
             $orderEntity = zbase_entity('custom_orders')->repository()->byId($orderId);
             $orderEntity->status = 2;
             $orderEntity->payment_merchant = zbase_request_input('payment_center', null);
             $orderEntity->paid_date_at = zbase_request_input('date', null);
             $orderEntity->payment_tracking_number = zbase_request_input('payment_tracking', null);
             $orderEntity->save();
             $orderEntity->sendPaymentReceiptToShane();
         }
     }
     zbase_view_pagetitle_set('Update Order');
     return $this->view(zbase_view_file('order.update'), compact('orderEntity'));
 }
示例#2
0
 protected function _contactUs()
 {
     $success = false;
     if ($this->isPost()) {
         if (!zbase_captcha_verify()) {
             return $this->buildFailedValidationResponse(zbase_request(), ['ReCAPTCHA Validation failed.']);
         }
         $validatorMessages = ['email.required' => _zt('Email Address is required.'), 'email.email' => _zt('Invalid email address.'), 'comment.required' => _zt('Message is required.'), 'name.required' => _zt('Name is required.')];
         $rules = ['email' => 'required|email', 'comment' => 'required', 'name' => 'required'];
         $valid = $this->validateInputs(zbase_request_inputs(), $rules, $validatorMessages);
         if (!empty($valid)) {
             $data = zbase_request_inputs();
             $success = zbase_messenger_email('contactus', zbase_request_input('email'), _zt(zbase_site_name() . ' - Contact Us Form - ' . zbase_request_input('name')), zbase_view_file_contents('email.contactus'), $data);
             if (!empty($success)) {
                 zbase_alert('success', _zt('Message sent!'));
                 zbase()->json()->setVariable('contact_success', 1);
                 if (!zbase_is_json()) {
                     return redirect(zbase_url_previous());
                 }
             } else {
                 zbase_alert('error', _zt('There was a problem sending your message. Kindly try again!'));
             }
         }
     }
 }
示例#3
0
 public function upload()
 {
     $image = false;
     $success = false;
     if ($this->isPost()) {
         if (!empty($_FILES['file'])) {
             $folder = zbase_storage_path() . '/zivsluck/site/images/';
             $filename = md5($_FILES['file']['name'] . date('Y-m-d-H'));
             $newFilename = zbase_file_name_from_file($_FILES['file']['name'], $filename, true);
             if (!file_exists($folder . $filename . '.png')) {
                 $newFilename = zbase_file_upload_image('file', $folder, $newFilename, 'png', []);
                 if (file_exists($newFilename)) {
                     $data = ['filename' => $filename];
                     $image = zbase_entity('images')->create($data);
                 }
             }
             $image = zbase_entity('images')->repository()->by('filename', $filename)->first();
         } else {
             $imagex = zbase_request_input('image', false);
             $delete = zbase_request_input('delete', false);
             if (!empty($imagex)) {
                 $image = zbase_entity('images')->repository()->by('filename', $imagex)->first();
                 if (!empty($image)) {
                     if (!empty($delete)) {
                         unlink($folder = zbase_storage_path() . '/zivsluck/site/images/' . $image->name() . '.png');
                         $image->delete();
                         return 1;
                     }
                     $image->font = zbase_request_input('font', null);
                     $image->material = zbase_request_input('material', null);
                     $image->tags = zbase_request_input('tags', null);
                     $image->save();
                     return 1;
                 }
                 return 0;
             }
         }
     }
     zbase_view_pagetitle_set('Images');
     return $this->view(zbase_view_file('site.upload'), compact('image'));
 }
示例#4
0
/**
 * Dx
 *
 * @link http://dennesabing.com
 * @author Dennes B Abing <*****@*****.**>
 * @license proprietary
 * @copyright Copyright (c) 2015 ClaremontDesign/MadLabs-Dx
 * @version 0.0.0.1
 * @since Mar 8, 2016 10:37:59 AM
 * @file widget.php
 * @project Expression project.name is undefined on line 13, column 15 in Templates/Scripting/EmptyPHP.php.
 * @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php.
 */
return ['type' => 'form', 'enable' => false, 'config' => ['nested' => true, 'elements' => ['header' => ['ui' => ['type' => 'component.pageHeader', 'id' => 'header', 'text' => 'Request to change password, enter your current password.']], 'password' => ['type' => 'password', 'id' => 'account_password', 'label' => 'Account Password', 'angular' => ['ngModel' => 'currentUser.accountPassword'], 'validations' => ['required' => ['enable' => function () {
    if (zbase_request_is_post()) {
        $tab = zbase_request_input('tab');
        if ($tab == 'email' || $tab == 'password') {
            return true;
        }
    }
    return false;
}, 'message' => 'Please enter your account password.'], 'accountPassword' => ['enable' => function () {
    if (zbase_request_is_post()) {
        $tab = zbase_request_input('tab');
        if ($tab == 'email' || $tab == 'password') {
            return true;
        }
    }
    return false;
}, 'message' => 'Account password don\'t match.']]]]]];
示例#5
0
 /**
  * Return the Export Filters
  * @return array
  */
 public function exportFilters()
 {
     return zbase_request_input($this->getWidgetPrefix('export') . 'Filter', []);
 }
示例#6
0
 /**
  * Create an element
  * @param array $element Element configuration
  * @param string $tabName The tabName the element belongs
  * @return Zbase\Ui\Form\ElementInterface
  */
 protected function _createElement($element, $tabName = null)
 {
     $e = \Zbase\Ui\Form\Element::factory($element);
     if (is_null($e)) {
         return;
     }
     $e->setAttribute('widgetEntity', $this->entity());
     if ($e instanceof \Zbase\Widgets\Type\FormInterface) {
         $e->form($this);
         if (empty($this->_entityIsDefault)) {
             $e->entity($this->_entity);
         }
     }
     if ($e instanceof \Zbase\Ui\Form\ElementInterface) {
         if (!empty($tabName)) {
             $e->setTab($tabName);
         }
         if ($this->isValueToSession()) {
             $e->setValue(zbase_session_get($e->id()));
         }
     }
     if ($e instanceof \Zbase\Widgets\EntityInterface) {
         $e->entity($this->_entity);
     }
     if ($e instanceof \Zbase\Widgets\Type\FormInterface) {
         $widgetElements = $e->elements();
         if (!empty($widgetElements)) {
             foreach ($widgetElements as $widgetElement) {
                 if (!empty($element['widget']) && !empty($element['prefix'])) {
                     $widgetElement->setIdPrefix($element['prefix']);
                     if ($this->isValueToSession()) {
                         $widgetElement->setValue(zbase_session_get($widgetElement->id()));
                     }
                 }
                 if (!empty($tabName)) {
                     if ($widgetElement instanceof \Zbase\Ui\Form\ElementInterface) {
                         $widgetElement->setTab($tabName);
                     }
                     if ($widgetElement instanceof \Zbase\Interfaces\ValidationInterface) {
                         if ($widgetElement->hasValidations()) {
                             //$currentTab = zbase_request_input('tab', false);
                             //if(zbase_request_method() == 'post' && !empty($currentTab))
                             //{
                             $widgetValidationRules = $widgetElement->getValidationRules($this->getAction());
                             if (!is_array($widgetValidationRules)) {
                                 $widgetValidationRules = [$widgetElement->getId() => $widgetValidationRules];
                             }
                             $this->_validationRules = array_replace_recursive($this->_validationRules, $widgetValidationRules);
                             $this->_validationMessages = array_replace_recursive($this->_validationMessages, $widgetElement->getValidationMessages($this->getAction()));
                             //}
                         }
                     }
                 }
             }
         } else {
             if ($e instanceof \Zbase\Ui\Form\ElementInterface) {
                 if ($e instanceof \Zbase\Interfaces\ValidationInterface) {
                     if ($e->hasValidations()) {
                         $widgetValidationRules = $e->getValidationRules($this->getAction());
                         if (!is_array($widgetValidationRules)) {
                             $widgetValidationRules = [$e->getId() => $widgetValidationRules];
                         }
                         $this->_validationRules = array_replace_recursive($this->_validationRules, $widgetValidationRules);
                         $this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
                     }
                 }
             }
         }
     }
     $currentTab = zbase_request_input('tab', false);
     if ($e instanceof \Zbase\Interfaces\ValidationInterface) {
         if ($e->hasValidations()) {
             $formTag = $this->_v('form_tab', true);
             if (zbase_request_method() == 'post' && empty($formTag) && !empty($currentTab)) {
                 if ($tabName == $currentTab) {
                     if (!isset($this->_validationRules['_tab' . $tabName])) {
                         $this->_validationRules['_tab' . $tabName] = [];
                     }
                     $this->_validationRules['_tab' . $tabName][$e->name()] = $e->getValidationRules($this->getAction());
                     $this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
                 }
             }
             //				if(zbase_request_method() == 'post' && empty($formTag) && !empty($currentTab))
             //				{
             //					if($tabName == $currentTab)
             //					{
             //						$this->_validationRules[$e->name()] = $e->getValidationRules($this->getAction());
             //						$this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
             //					}
             //				}
             //				else
             //				{
             //					$this->_validationRules[$e->name()] = $e->getValidationRules($this->getAction());
             //					$this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
             //				}
         }
         //			if(zbase_request_method() == 'post')
         //			{
         //				var_dump(zbase_request_inputs());
         //				var_dump($currentTab . '-' . $tabName);
         //			}
     }
     return $e;
 }
示例#7
0
 /**
  * Add a Tab
  * @param \Zbase\UIs\Tab $tab
  * @return \Zbase\UIs\Tabs
  */
 public function add(UIs\Tab $tab)
 {
     if ($tab->enabled() && $tab->hasAccess()) {
         $activeTab = zbase_request_input('tab', false);
         if (empty($activeTab)) {
             $activeTab = zbase_session_get('sessiontab', false);
         }
         if (!empty($activeTab)) {
             $tab->setActive(false);
             if ($tab->tabId() == $activeTab) {
                 $tab->setActive(true);
             }
         }
         if ($tab->isActive()) {
             $this->_hasActiveTab = true;
         }
         $this->_tabs[] = $tab;
     }
     return $this;
 }
示例#8
0
/**
 * Return the Response
 * @param mixed $response
 * @return mixed
 */
function zbase_response($response)
{
    // HTTP/1.1 204 No Content
    //	$apiResponse = zbase()->json()->getVariable('api');
    //	if(!empty($apiResponse) && $apiResponse instanceof \Zbase\Exceptions\HttpException && $apiResponse->getStatusCode() == 204)
    //	{
    //		$response->header('HTTP/1.1 204 No Content');
    //		return $response;
    //	}
    $returnNoContent = '';
    $errorResponse = false;
    $xmlResponse = false;
    $responseFormat = zbase_response_format();
    if (zbase_is_json()) {
        $responseFormat = 'json';
    }
    if ($responseFormat == 'json' || zbase_request_is_ajax()) {
        $jsonResponse = true;
    }
    if ($responseFormat == 'xml') {
        $xmlResponse = true;
    }
    if (zbase_is_angular_template()) {
        $responseFormat = 'html';
        $jsonResponse = false;
    }
    if (!empty($jsonResponse)) {
        $formId = zbase_request_input('_formId', null);
        if (!empty($formId)) {
            zbase()->json()->setVariable('_formId', $formId);
        }
        zbase()->json()->setVariable('_route', zbase_route_name());
        zbase()->json()->setVariable('_package', zbase_view_template_package());
        $code = 200;
        if ($response instanceof \RuntimeException) {
            $code = $response->getStatusCode();
            zbase()->json()->setVariable('statusCode', $code);
            if ($code !== 200) {
                $errorResponse = true;
                zbase()->json()->setVariable('statusMessage', $response->getStatusMessage());
            }
        }
        /**
         * its ajax, but method is GET
         */
        if (empty($errorResponse)) {
            $tokenResponse = zbase_request_input('token', zbase_request_query_input('token', false));
            if (!$tokenResponse) {
                zbase()->json()->setVariable('_token', zbase_csrf_token());
            }
        }
        zbase()->json()->setVariable('_alerts', ['errors' => zbase_alerts('error'), 'messages' => zbase_alerts('success'), 'info' => zbase_alerts('info'), 'warning' => zbase_alerts('warning')]);
        $jsonScripts = zbase()->json()->getVariable('_html_script');
        $jsonScriptReturn = '';
        if (!empty($jsonScripts)) {
            foreach ($jsonScripts as $jScripts) {
                if (!empty($jScripts[0])) {
                    $jScripts[0] = str_replace(array('<script type="text/javascript">', '</script>'), '', $jScripts[0]);
                    $jsonScriptReturn .= $jScripts[0] . ';';
                }
            }
        }
        zbase()->json()->setVariable('_html_script', str_replace(';;', ';', $jsonScriptReturn));
        $forceResponse = zbase_request_input('forceResponse', zbase_request_query_input('forceResponse', false));
        /**
         * JSONP Callback
         */
        $jsonCallback = zbase_request_query_input('callback', zbase_request_query_input('jsonp', false));
        if (!$forceResponse) {
            zbase_alerts_render();
            if (!empty($jsonCallback)) {
                return response()->json(zbase()->json()->getVariables(), $code)->setCallback($jsonCallback);
            } else {
                return response()->json(zbase()->json()->getVariables(), $code);
            }
        }
    }
    if ($response instanceof \RuntimeException) {
        if ($response->getStatusCode() == '302') {
            if (zbase_is_json()) {
                zbase_alerts_render();
                if (!empty($jsonCallback)) {
                    return response()->json(zbase()->json()->getVariables(), 302)->setCallback($jsonCallback);
                } else {
                    return response()->json(zbase()->json()->getVariables(), 302);
                }
            }
        }
        return $response->render(zbase_request(), $response);
    }
    /**
     * REsponse with a javascript code
     */
    if ($responseFormat == 'javascript') {
        $response = \Response::make($response, 200);
        $response->header('Content-Type', 'application/javascript');
    }
    return $response;
}
示例#9
0
}, 'json-profile' => function () {
    return zbase_config_get('modules.account.widgets.controller.profile', ['account-profile' => null]);
}, 'image' => function () {
    return zbase_config_get('modules.account.widgets.controller.image', ['account-image' => null]);
}, 'resend-email-verification' => function () {
    zbase_auth_user()->resendEmailVerificationCode();
    return zbase_redirect()->to(zbase_url_previous());
}, 'json-resend-email-verification' => function () {
    zbase_auth_user()->resendEmailVerificationCode();
    return zbase_redirect()->to(zbase_url_previous());
}, 'json-telegram-check' => function () {
    $r = zbase()->telegram()->checkUserCode(zbase_auth_user());
    if ($r) {
        zbase()->json()->addVariable('telegramHooked', 1);
        return zbase_redirect()->to(zbase_url_from_route('admin.account'));
    } else {
        dd('waiting to hooked...');
    }
}, 'telegram-disable' => function () {
    zbase()->telegram()->disableUserTelegram(zbase_auth_user());
    return redirect()->to(zbase_url_previous());
}, 'email-verify' => function () {
    $emailAddress = zbase_route_input('task');
    $code = zbase_request_input('c');
    $user = zbase_user_by('email', $emailAddress);
    if (!empty($user)) {
        $user->verifyEmailAddress($code);
        return zbase_redirect(zbase_url_from_route('home'));
    }
    return zbase_abort(404);
}]]];
示例#10
0
 /**
  * Join Query
  * @param array $filters Array of Filters
  * @param array $sorting Array of Sorting
  * @param array $options some options
  * @return array
  */
 public function querySearchFilters($filters, $options = [])
 {
     $query = zbase_request_input('adminUsersSearchQuery', !empty($options['query']) ? $options['query'] : null);
     if (!empty($query)) {
         $queries = [];
         if (preg_match('/\\,/', $query) > 0) {
             $queries = explode(',', $query);
         } else {
             $queries[] = $query;
         }
         foreach ($queries as $query) {
             /**
              * Searching for Role
              */
             if (preg_match('/role\\:/', $query) > 0) {
                 $stringFound = true;
                 $filters['rolename.role_name'] = ['like' => ['field' => 'rolename.role_name', 'value' => '%' . trim(str_replace('role:', '', $query)) . '%']];
             }
             /**
              * Searching for City
              */
             if (preg_match('/city\\:/', $query) > 0) {
                 $stringFound = true;
                 $filters['address.city'] = ['like' => ['field' => 'address.city', 'value' => '%' . trim(str_replace('city:', '', $query)) . '%']];
             }
             /**
              * Searching for State
              */
             if (preg_match('/state\\:/', $query) > 0) {
                 $stringFound = true;
                 $filters['address.state'] = ['like' => ['field' => 'address.state', 'value' => '%' . trim(str_replace('state:', '', $query)) . '%']];
             }
             /**
              * Searching for Country
              */
             if (preg_match('/country\\:/', $query) > 0) {
                 $stringFound = true;
                 $filters['address.country'] = ['like' => ['field' => 'address.country', 'value' => '%' . trim(str_replace('country:', '', $query)) . '%']];
             }
             /**
              * Searching for Name
              */
             if (preg_match('/name\\:/', $query) > 0) {
                 $stringFound = true;
                 $filters['name'] = function ($q) use($query) {
                     $name = trim(str_replace('name:', '', $query));
                     return $q->orWhere('profile.first_name', 'LIKE', '%' . $name . '%')->orWhere('profile.last_name', 'LIKE', '%' . $name . '%');
                 };
             }
             /**
              * Searching for Email
              */
             if (preg_match('/\\@/', $query) > 0) {
                 $stringFound = true;
                 $filters['users.email'] = ['eq' => ['field' => 'users.email', 'value' => $query]];
             }
             /**
              * Searching Id
              */
             if (is_numeric($query)) {
                 $stringFound = true;
                 $filters['users.user_id'] = ['eq' => ['field' => 'users.user_id', 'value' => intval($query)]];
             }
             if (empty($stringFound)) {
                 $filters['users.name'] = function ($q) use($query) {
                     return $q->orWhere('users.name', 'LIKE', '%' . $query . '%')->orWhere('users.location', 'LIKE', '%' . $query . '%')->orWhere('users.email', 'LIKE', '%' . $query . '%')->orWhere('users.username', 'LIKE', '%' . $query . '%');
                 };
             }
         }
     }
     return $filters;
 }
 /**
  * Send a reset link to the given user.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postEmail(Request $request)
 {
     // $this->validate($request, ['email' => 'required|email|exists:' . zbase_config_get('entity.user.table.name') . ',email']);
     $entity = zbase()->entity('user', [], true);
     $user = $entity->repo()->by('email', zbase_request_input('email'))->first();
     if (!empty($user)) {
         $broker = $this->getBroker();
         $response = \Password::broker($broker)->sendResetLink($this->getSendResetLinkEmailCredentials($request), $this->resetEmailBuilder());
         $user->lostPassword();
     }
     zbase()->json()->setVariable('password_success', 1);
     zbase()->json()->setVariable('_redirect', zbase_url_previous());
     if (!zbase_is_json()) {
         return redirect()->back()->with('status', trans(\Password::RESET_LINK_SENT));
     }
 }
示例#12
0
/**
 * true if HTTP Accept header is application/json
 *
 * @return boolean
 */
function zbase_is_json()
{
    if (zbase_request_query_input('jsonp', false)) {
        return true;
    }
    if (zbase_request_query_input('json', false)) {
        return true;
    }
    if (zbase_is_post() && zbase_request_input('json', false)) {
        return true;
    }
    return \Request::wantsJson();
}
示例#13
0
 /**
  * Return the entity
  * @return Zbase\Widget\EntityInterface
  */
 public function entity()
 {
     if (empty($this->hasEntity())) {
         return false;
     }
     if (is_null($this->_entity)) {
         $entityName = $this->_v('entity.name', null);
         if (!empty($this->_nodeSupport)) {
             $entityName = $this->getNodeNamespace() . '_' . strtolower($this->_nodeName);
         }
         if (!is_null($entityName)) {
             $entity = $this->_v('entity.entity', null);
             if ($entity instanceof \Zbase\Entity\Laravel\Entity) {
                 $this->_entityObject = zbase()->entity($entityName, [], true);
                 $this->_entity = $entity;
                 return $this->_entity;
             }
             if ($entity instanceof \Zbase\Post\PostInterface) {
                 $this->_entityObject = $entity;
                 $this->_entity = $entity;
                 return $this->_entity;
             }
             $this->_entity = $this->_entityObject = $entity = zbase()->entity($entityName, [], true);
             $repoById = $this->_v('entity.repo.byId', null);
             $repoByFilter = $this->_v('entity.repo.byFilter', null);
             if (is_null($repoById)) {
                 $repoById = $this->_v('entity.repo.byAlphaId', null);
                 if (!empty($repoById)) {
                     $byAlpha = true;
                 } else {
                     $repoById = $this->_v('entity.repo.bySlug', null);
                     if (!empty($repoById)) {
                         $bySlug = true;
                     }
                 }
             }
             if (is_array($repoById)) {
                 if (!empty($repoById['route'])) {
                     $id = zbase_route_input($repoById['route']);
                 }
                 if ($this->isNodeCategoryBrowsing()) {
                     $repoItemBySlug = $this->_v('entity.repo.item.bySlug', null);
                     $repoItemByAlpha = $this->_v('entity.repo.item.byAlpha', null);
                     $repoItemById = $this->_v('entity.repo.item.byId', null);
                     /**
                      * Browse by category
                      * /CategorySlug/ - should show all category items
                      * /CategorySlug/ItemName - show item
                      *
                      * Module should have a "default" entry as the wildcard catchAll action
                      */
                     if (!empty($repoItemByAlpha)) {
                         $itemRouteParameterName = $this->_v('entity.repo.item.byAlpha.route', null);
                         $childAlphaId = zbase_route_input($itemRouteParameterName);
                         if (!empty($childAlphaId)) {
                             $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->byAlphaId($childAlphaId);
                             if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) {
                                 $this->setViewFile(zbase_view_file_contents('errors.404'));
                                 return zbase_abort(404);
                             }
                         }
                     }
                     if (!empty($repoItemBySlug)) {
                         $itemRouteParameterName = $this->_v('entity.repo.item.bySlug.route', null);
                         $childAlphaId = zbase_route_input($itemRouteParameterName);
                         if (!empty($childAlphaId)) {
                             $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->bySlug($childAlphaId);
                             if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) {
                                 $this->setViewFile(zbase_view_file_contents('errors.404'));
                                 return zbase_abort(404);
                             }
                         }
                     }
                     if (!empty($repoItemById)) {
                         $itemRouteParameterName = $this->_v('entity.repo.item.byId.route', null);
                         $childAlphaId = zbase_route_input($itemRouteParameterName);
                         if (!empty($childAlphaId)) {
                             $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->byId($childAlphaId);
                             if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) {
                                 $this->setViewFile(zbase_view_file_contents('errors.404'));
                                 return zbase_abort(404);
                             }
                         }
                     }
                 }
                 if (!empty($repoById['request']) && zbase_is_post() == 'post') {
                     $id = zbase_request_input($repoById['request']);
                 }
                 if (!empty($id)) {
                     $filters = $this->_v('entity.filter.query', []);
                     $sorting = $this->_v('entity.sorting.query', []);
                     $selects = ['*'];
                     $joins = [];
                     $this->_urlHasRequest = true;
                     if ($this->isNode()) {
                         zbase()->json()->addVariable('id', $id);
                         if (!empty($repoById) && !empty($id) && empty($byAlpha) && empty($bySlug)) {
                             $filters['id'] = ['eq' => ['field' => $entity->getKeyName(), 'value' => $id]];
                         }
                         if ($this->isCurrentUser()) {
                             $filters['user'] = ['eq' => ['field' => 'user_id', 'value' => zbase_auth_user()->id()]];
                         }
                         if ($this->isPublic()) {
                             $filters['status'] = ['eq' => ['field' => 'status', 'value' => 2]];
                         }
                         if (!empty($byAlpha)) {
                             $filters['alpha'] = ['eq' => ['field' => 'alpha_id', 'value' => $id]];
                         }
                         if (!empty($bySlug)) {
                             $filters['slug'] = ['eq' => ['field' => 'slug', 'value' => $id]];
                         }
                         if (method_exists($entity, 'querySelects')) {
                             $selects = $entity->querySelects($filters, ['widget' => $this]);
                         }
                         if (method_exists($entity, 'queryJoins')) {
                             $joins = $entity->queryJoins($filters, $this->getRequestSorting(), ['widget' => $this]);
                         }
                         if (method_exists($entity, 'querySorting')) {
                             $sorting = $entity->querySorting($sorting, $filters, ['widget' => $this]);
                         }
                         if (method_exists($entity, 'queryFilters')) {
                             $filters = $entity->queryFilters($filters, $sorting, ['widget' => $this]);
                         }
                         /**
                          * Merge filters from widget configuration
                          * entity.filter.query
                          */
                         $filters = array_merge($filters, $this->_v('entity.filter.query', []));
                         $sorting = array_merge($sorting, $this->_v('entity.sorting.query', []));
                         $action = $this->getAction();
                         $debug = zbase_request_query_input('__widgetEntityDebug', false);
                         if ($this->isAdmin()) {
                             if ($action == 'restore' || $action == 'ddelete') {
                                 return $this->_entity = $entity->repository()->onlyTrashed()->all($selects, $filters, $sorting, $joins)->first();
                             }
                         } else {
                             if ($entity->hasSoftDelete() && $this->isCurrentUser()) {
                                 if ($action == 'restore' || $action == 'ddelete') {
                                     return $this->_entity = $entity->repository()->onlyTrashed()->all($selects, $filters, $sorting, $joins)->first();
                                 }
                                 return $this->_entity = $entity->repository()->setDebug($debug)->withTrashed()->all($selects, $filters, $sorting, $joins)->first();
                             }
                         }
                         return $this->_entity = $entity->repository()->setDebug($debug)->all($selects, $filters, $sorting, $joins)->first();
                     }
                 }
             } else {
                 if (!empty($repoByFilter)) {
                     $filters = [];
                     $sorting = [];
                     $selects = ['*'];
                     $joins = [];
                     $singleRow = $this->_v('entity.singlerow', true);
                     if ($this->isCurrentUser()) {
                         $filters['user'] = ['eq' => ['field' => 'user_id', 'value' => zbase_auth_user()->id()]];
                     }
                     if ($this->isPublic()) {
                         $filters['status'] = ['eq' => ['field' => 'status', 'value' => 2]];
                     }
                     $filters = array_merge($filters, $this->_v('entity.filter.query', []));
                     $sorting = array_merge($sorting, $this->_v('entity.sorting.query', []));
                     if (!empty($singleRow)) {
                         return $this->_entity = $entity->repository()->all($selects, $filters, $sorting, $joins)->first();
                     } else {
                         return $this->_entity = $entity->repository()->all($selects, $filters, $sorting, $joins);
                     }
                 }
             }
             $repoMethod = $this->_v('entity.method', null);
             if (!is_null($repoMethod)) {
                 return $this->_entity = $this->_entityObject->{$repoMethod}();
             }
             $this->_entityIsDefault = true;
             return $this->_entity = $this->_entityObject;
         }
     }
     return $this->_entity;
 }
示例#14
0
 /**
  * Process initial authentication
  * Checking if user can Auth
  */
 public function authenticated(Request $request, $user)
 {
     if (!$user->canAuth()) {
         \Auth::logout();
     }
     $user->log('user::authenticated');
     $user->authenticated();
     if (zbase_route_username()) {
         $usernameRoutePrefix = zbase_route_username_prefix();
         $redirect = zbase_request_input('redirect', zbase_session_get('__loginRedirect', zbase_url_from_route('home', [$usernameRoutePrefix => $user->username()])));
     } else {
         $redirect = !empty($this->redirectTo) ? $this->redirectTo : zbase_request_input('redirect', zbase_session_get('__loginRedirect', zbase_url_from_route('home')));
     }
     zbase()->json()->setVariable('_redirect', $redirect);
     zbase()->json()->setVariable('login_success', 1);
     return redirect()->intended($redirect);
 }
示例#15
0
    /**
     * SCripts when this content/view is displayed on innerContent via Ajax
     *
     * @param boolean $load Data is Loading else we are leaving the page, going back
     * @return void
     */
    public function postPageOnInnerContentScript($tag = null)
    {
        if (!empty(zbase_request_input('_innercontent'))) {
            if (method_exists($this, 'pageOnInnerContentScript')) {
                $this->pageOnInnerContentScript($tag);
            }
            $postHtmlId = $this->postHtmlId();
            $away = zbase_request_input('_innercontentaway', false);
            $tableRowId = zbase_request_input('_datatableRow', false);
            $innerContentId = zbase_request_input('_innerContentId', false);
            /**
             * Currently viewing the data
             */
            $innerContentView = zbase_request_input('_innerContentView', false);
            if (empty($away)) {
                if (!empty($innerContentView)) {
                    zbase()->json()->setVariable('_html_selector_replace', ['h3.page-title span.' . $this->postHtmlCommonId() => '<span class="' . $this->postHtmlCommonId() . '">' . zbase()->view()->title() . '<small>' . zbase()->view()->subTitle() . '</small></span>'], true);
                } else {
                    if (!empty($tableRowId) && !empty($innerContentId)) {
                        zbase()->json()->setVariable('_html_selector_remove', ['.' . $this->postHtmlCommonId() => ''], true);
                        zbase()->json()->setVariable('_html_selector_append', ['.page-breadcrumb.breadcrumb' => '<li class="' . $this->postHtmlCommonId() . '"><i class="fa fa-angle-right"></i><a title="' . $this->postDisplayText() . '" href="#">' . $this->postDisplayText() . '</a></li>'], true);
                        zbase()->json()->setVariable('_html_selector_append', ['h3.page-title' => '<span class="' . $this->postHtmlCommonId() . '">' . zbase()->view()->title() . '<small>' . zbase()->view()->subTitle() . '</small></span>'], true);
                        zbase()->json()->setVariable('_html_selector_hide', ['.zbase-page-title' => ''], true);
                        $script = 'jQuery(\'#' . $innerContentId . '\').closest(\'.zbase-widget-wrapper-datatable\').hide();jQuery(\'.breadcrumb li\').eq(2).find(\'a\').click(function(e){
								e.preventDefault();
								window.history.pushState(\'\',\'' . zbase()->view()->title() . '\',\'' . zbase_url_previous() . '\');
								jQuery(\'#' . $innerContentId . '\').closest(\'.zbase-widget-wrapper-datatable\').show();
								jQuery(\'#' . $innerContentId . '\').closest(\'.zbase-widget-wrapper-datatable\').siblings().remove();
								jQuery(\'h3.page-title span.' . $this->postHtmlCommonId() . '\').remove();
								jQuery(\'h3.page-title span.zbase-page-title\').show();
								jQuery(\'.breadcrumb li.' . $this->postHtmlCommonId() . '\').remove();
							})';
                        zbase()->json()->setVariable('_html_script', [$script], true);
                    }
                }
            } else {
                $script = 'jQuery(\'#' . $innerContentId . '\').closest(\'.zbase-widget-wrapper-datatable\').show();
						jQuery(\'#' . $innerContentId . '\').closest(\'.zbase-widget-wrapper-datatable\').siblings().remove();
						jQuery(\'h3.page-title span.' . $this->postHtmlCommonId() . '\').remove();
						jQuery(\'h3.page-title span.zbase-page-title\').show();
						jQuery(\'.breadcrumb li.' . $this->postHtmlCommonId() . '\').remove();';
                zbase()->json()->setVariable('_html_script', [$script], true);
            }
        } else {
            zbase()->json()->setVariable('_html_selector_replace', ['.page-breadcrumb.breadcrumb' => zbase_view_render(zbase_view_file('partial.breadcrumb', zbase_section()))], true);
            zbase()->json()->setVariable('_html_selector_html', ['.page-title' => zbase()->view()->title() . '<small>' . zbase()->view()->subTitle() . '</small>'], true);
        }
    }
示例#16
0
/**
 * Verify Recaptcha
 * @return boolean
 */
function zbase_captcha_verify()
{
    $enable = zbase_config_get('recaptcha.enable', false);
    $secretKey = zbase_config_get('recaptcha.secretkey', false);
    $response = zbase_request_input('g-recaptcha-response', false);
    if ($response !== false && !empty($secretKey) && !empty($enable)) {
        if (!empty($response)) {
            $response = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretKey . '&response=' . $response . '&remoteip=' . zbase_ip()), TRUE);
            if ($response['success'] == FALSE) {
                zbase_alert(\Zbase\Zbase::ALERT_ERROR, 'ReCAPTCHA Validation Failed.');
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
    return true;
}
示例#17
0
/**
 * Retrieve an input value by $key
 *
 * @param string $key
 * @param mixed $default
 * @return mixed
 */
function zbase_form_input($key, $default = null)
{
    return zbase_request_input($key, $default);
}