Пример #1
0
 /**
  * HTML the ui
  * @return string
  */
 public function __toString()
 {
     $this->prepare();
     try {
         if (!is_null($this->_viewFile) && empty($this->_rendered)) {
             if (!zbase_request_is_ajax()) {
                 zbase()->view()->multiAdd($this->_v('view.library', false));
             }
             $this->_viewParams['ui'] = $this;
             $str = $this->preTag();
             $str .= $this->htmlPreContent();
             if (!empty($this->_viewFileContent)) {
                 $str .= zbase_view_render(zbase_view_file_contents($this->_viewFile), $this->getViewParams());
             } else {
                 $str .= zbase_view_render($this->_viewFile, $this->getViewParams());
             }
             $str .= $this->htmlPostContent();
             $str .= $this->postTag();
             $this->_rendered = true;
             return $str;
         }
         return '';
     } catch (\Exception $e) {
         if (zbase_is_dev()) {
             dd($e);
         }
         zbase_abort(500);
     }
 }
Пример #2
0
/**
 * Render alerts
 *
 * @param string $type
 * @return html
 */
function zbase_alerts_render($type = null)
{
    if (!empty($type)) {
        $alerts = zbase_alerts($type);
        if (!empty($alerts)) {
            if (zbase_request_is_ajax()) {
                zbase()->json()->setVariable($type, $alerts);
                return;
            }
            $params = ['type' => $type, 'alerts' => $alerts];
            $template = zbase_view_file_contents(zbase_config_get('view.templates.alerts.' . $type, 'alerts.' . $type));
            return zbase_view_render($template, $params);
        }
        return null;
    }
    if (zbase_request_is_ajax()) {
        zbase_alerts_render('error');
        zbase_alerts_render('warning');
        zbase_alerts_render('success');
        zbase_alerts_render('info');
    } else {
        $str = '';
        $str .= zbase_alerts_render('error');
        $str .= zbase_alerts_render('warning');
        $str .= zbase_alerts_render('success');
        $str .= zbase_alerts_render('info');
        return $str;
    }
}
Пример #3
0
 /**
  * Event after Action
  * @param string $action
  * @param string $url The Default URL to redirect
  */
 protected function _postEvent($action)
 {
     if ($this->isPublic() && $this->isNode() && $this->isCreating()) {
         return zbase_redirect()->to($this->entity()->alphaUrl());
     }
     $isAjax = zbase_request_is_ajax();
     $requestMethod = strtolower(zbase_request_method());
     if ($isAjax) {
         if ($requestMethod == 'post') {
             $e = $this->_v('event.' . zbase_section() . '.' . $action . '.post-json.post', $this->_v('event.' . $action . '.post-json'));
         } else {
             $e = $this->_v('event.' . zbase_section() . '.' . $action . '.post-json', $this->_v('event.' . zbase_section() . '.' . $action . '.post'));
         }
     } else {
         if ($requestMethod == 'post') {
             $e = $this->_v('event.' . zbase_section() . '.' . $action . '.post.post', $this->_v('event.' . $action . '.post.post', null));
         } else {
             $e = $this->_v('event.' . zbase_section() . '.' . $action . '.post', $this->_v('event.' . $action . '.post', null));
         }
     }
     if (is_null($e)) {
         if (zbase_is_back()) {
             if ($this->isCreating()) {
                 $action = 'update';
             }
             $byAlphaId = $this->_v('entity.repo.byAlphaId.route', false);
             if ($this->entityIsPostInterface($this->entity())) {
                 if (!empty($byAlphaId)) {
                     $params = ['action' => $action, 'id' => $this->entity()->postAlphaId()];
                 } else {
                     $params = ['action' => $action, 'id' => $this->entity()->postId()];
                 }
             } else {
                 if (!empty($byAlphaId)) {
                     $params = ['action' => $action, 'id' => $this->entity()->alphaId()];
                 } else {
                     $params = ['action' => $action, 'id' => $this->entity()->id()];
                 }
             }
         } else {
             $params = ['action' => $action, 'id' => $this->entity()->alphaId()];
         }
         if ($action == 'delete') {
             $params = [];
         }
         $url = $this->getModule()->url(zbase_section(), $params);
         if ($action == 'restore' || $action == 'ddelete') {
             $url = zbase_url_previous();
         }
     }
     if (!empty($e)) {
         if (!empty($e['data'])) {
             if ($isAjax) {
                 zbase()->json()->addVariables($e['data']);
             }
         }
         if (!empty($e['route'])) {
             $params = zbase_route_inputs();
             if (!empty($e['route']['params'])) {
                 $params = array_merge($params, $e['route']['params']);
             }
             if (zbase_is_back()) {
                 $byAlphaId = $this->_v('entity.repo.byAlphaId.route', false);
                 if (!empty($byAlphaId)) {
                     $params['id'] = $this->entity()->alphaId();
                 } else {
                     $params['id'] = $this->entity()->id();
                 }
             }
             if ($action == 'ddelete') {
                 if (isset($params['id']) && isset($params['action'])) {
                     unset($params['id']);
                     unset($params['action']);
                 }
             }
             $e['route']['params'] = $params;
             $url = zbase_url_from_config($e);
         }
         $toUrl = zbase_value_get($e, 'url', false);
         if (!empty($toUrl)) {
             $url = $toUrl;
         }
     }
     $enableRedirect = $this->_v('event.' . zbase_section() . '.' . $action . '.post.redirect.enable', $this->_v('event.' . $action . '.post.redirect.enable', true));
     if (!empty($url) && !empty($enableRedirect)) {
         return zbase_redirect()->to($url);
     }
     return true;
 }
Пример #4
0
 public function controllerIndex()
 {
     if (!$this->getModule()->hasAccess()) {
         if (zbase_auth_has()) {
             return $this->unathorized(_zt('You don\'t have enough access to the resource.'));
         } else {
             return redirect()->to(zbase_url_from_route('login'));
         }
     }
     /**
      * Check for widgets
      */
     $widgetsAction = $action = str_replace('.', '-', $this->getRouteParameter('action', 'index'));
     $requestMethod = zbase_request_method();
     if (!empty($this->nodeName)) {
         $widgetsAction = $requestMethod . '-node-' . $this->nodeName . '-' . $action;
         $htmls = [];
     }
     $isAjax = zbase_request_is_ajax();
     if ($isAjax) {
         $widgetsAction = (!empty($this->nodeName) ? $requestMethod . '-node-' . $this->nodeName . '-' : '') . 'json-' . $action;
         $htmls = [];
     }
     if ($this->getModule()->hasAction($requestMethod . '-' . $action)) {
         $widgetsAction = $requestMethod . '-' . $action;
         $action = $widgetsAction;
         $htmls = [];
     }
     $widgets = $this->getModule()->pageProperties($action)->widgetsByControllerAction($widgetsAction);
     if (count($widgets) == 1) {
         $firstWidget = collect($widgets)->first();
         if ($firstWidget instanceof \Zbase\Widgets\WidgetInterface) {
             $firstWidget->pageProperties($widgetsAction);
         }
     }
     if (!is_array($widgets) && $widgets instanceof \Illuminate\Http\RedirectResponse) {
         return $widgets;
     }
     zbase()->json()->addVariable('_widget', $this->getModule()->id() . '_' . str_replace('-', '', $action));
     if (zbase_is_dev()) {
         zbase()->json()->addVariable(__METHOD__, $widgetsAction);
         if (zbase_request_is_post()) {
             zbase()->json()->addVariable('_POST_PARAMETERS', zbase_request_inputs());
         }
         zbase()->json()->addVariable('_ROUTE_PARAMETERS', zbase_route_inputs());
         zbase()->json()->addVariable('_GET_PARAMETERS', zbase_request_query_inputs());
     }
     // dd($this->getModule(), $widgetsAction, $widgets);
     if (empty($widgets)) {
         return zbase_abort(404);
     }
     foreach ($widgets as $widget) {
         if (!empty($this->nodeName)) {
             zbase()->json()->addVariable('node', ['prefix' => $this->getModule()->nodeNamespace(), 'name' => $this->nodeName, 'support' => 1]);
             $widget->setNodename($this->nodeName)->setNodeSupport(true);
         }
         if ($widget instanceof \Zbase\Widgets\ControllerInterface) {
             $v = $widget->validateWidget($action);
             if ($v instanceof \Illuminate\Contracts\Validation\Validator) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('errors', $v->errors()->getMessages());
                     return new \Illuminate\Http\JsonResponse($v->errors()->getMessages(), 422);
                 } else {
                     return redirect()->to($this->getRedirectUrl())->withInput(zbase_request_inputs())->withErrors($v->errors()->getMessages());
                 }
             }
             $ret = $widget->controller($this->getRouteParameter('action', 'index'));
             if ($ret instanceof \Zbase\Exceptions\NotFoundHttpException) {
                 return $this->notFound();
             }
             if ($ret instanceof \Zbase\Exceptions\UnauthorizedException) {
                 return $this->unathorized();
             }
             if ($ret instanceof \Zbase\Exceptions\Exception) {
                 return $this->error();
             }
             if ($ret instanceof \Illuminate\Http\RedirectResponse) {
                 if ($isAjax) {
                     zbase()->json()->addVariable('redirect', $ret->getTargetUrl());
                 } else {
                     return $ret;
                 }
             }
             if (zbase_is_json()) {
                 zbase_response_format_set('json');
                 $jsonIndexName = $widget->getWidgetPrefix();
                 if (zbase_is_angular()) {
                     if ($widget instanceof \Zbase\Widgets\Type\Datatable) {
                         $angularTemplate = zbase_angular_widget_datatable($this->getModule(), $widget);
                         $jsonIndexName = $angularTemplate['serviceName'];
                     }
                 }
                 if (zbase_is_dev()) {
                     zbase()->json()->addVariable('$jsonIndexName', $jsonIndexName);
                 }
                 if (!$widget->isExporting()) {
                     zbase()->json()->addVariable($jsonIndexName, $widget->toArray());
                 }
             } else {
                 if ($isAjax) {
                     $htmls[str_replace('-', '_', $widget->id())] = $widget->render();
                 }
             }
             $widget->pageProperties($widgetsAction);
         }
     }
     if (!empty($isAjax)) {
         zbase()->json()->addVariable('_widgets', 1);
         zbase()->json()->addVariable('html', $htmls);
     } else {
         return $this->view(zbase_view_file('module.index'), array('module' => $this->getModule(), 'widgets' => $widgets));
     }
 }
Пример #5
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;
}
Пример #6
0
 /**
  * Page Meta Properties
  *
  * @return void
  */
 public function postPageProperties($widget = null)
 {
     if (method_exists($this, 'pageProperties')) {
         $this->pageProperties($widget);
     } else {
         $breadcrumbs = zbase_view_breadcrumb_get();
         $breadcrumbs[] = ['label' => $this->postDisplayText(), 'link' => '#'];
         $page['title'] = $this->postDisplayText() . $this->postStatusText();
         $page['headTitle'] = $this->postDisplayText();
         $page['breadcrumbs'] = $breadcrumbs;
         zbase_view_page_details(['page' => $page]);
     }
     $postHtmlId = $this->postHtmlId();
     if (zbase_request_is_ajax()) {
         $this->postPageOnInnerContentScript();
     }
 }
Пример #7
0
<br />
<br />
<br />
MESSAGE: -------------------
<br />
<?php 
    echo $message;
}
?>

<br />
<br />
<br />
--- DETAILS:
<?php 
$error = 'Date: ' . zbase_date_now()->format('Y-m-d h:i:s A') . "<br />";
$error .= 'URL: ' . zbase_url_uri() . "<br />";
$error .= 'Is Posting: ' . (zbase_request_is_post() ? 'Yes' : 'No') . "<br />";
$error .= 'Is AJAX: ' . (zbase_request_is_ajax() ? 'Yes' : 'No') . "<br />";
$error .= 'Data: ' . json_encode(zbase_request_inputs()) . "<br />";
$error .= 'Routes: ' . json_encode(zbase_route_inputs()) . "<br />";
$error .= 'IP Address: ' . zbase_ip() . "<br /><br /";
if (zbase_auth_has()) {
    $user = zbase_auth_user();
    $error .= 'User: '******' ' . $user->username() . '[' . $user->id() . ']' . "<br />";
}
echo $error;
?>

<?php 
echo zbase_view_render(zbase_view_file_contents('email.footer'));
Пример #8
0
			<?php 
    if (!empty($onFormSubmit)) {
        ?>
				jQuery('#<?php 
        echo $ui->getHtmlId();
        ?>
Uploader').closest('form').find('[type="submit"]').attr('id','<?php 
        echo $ui->getHtmlId();
        ?>
UploaderSubmitButton');
			<?php 
    }
    ?>
		</script>
		<?php 
    if (zbase_request_is_ajax()) {
        zbase()->json()->setVariable('_html_script', [ob_get_clean()], true);
    } else {
        zbase_view_script_add('fileupload' . $formId, ob_get_clean(), true);
    }
    ?>
		<script id="template-upload" type="text/x-tmpl">
			{% for (var i=0, file; file=o.files[i]; i++) { %}
				<tr class="template-upload fade">
					<td>
						<span class="preview"></span>
					</td>
					<td>
						<p class="name">{%=file.name%}</p>
						{% if (file.error) { %}
							<div><span class="label label-danger">Error</span> {%=file.error%}</div>
Пример #9
0
 /**
  * Check if request is from ajax
  *
  * @return boolean
  */
 public function isAjax()
 {
     return zbase_request_is_ajax();
 }