/**
  * Display the password reset view for the given token.
  *
  * @param  string  $token
  * @return \Illuminate\Http\Response
  */
 public function getReset($token = null)
 {
     if (is_null($token)) {
         return $this->notfound();
     }
     $email = zbase_request_query_input('email', null);
     return $this->view(zbase_view_file('auth.password.reset'), array('token' => $token, 'email' => $email));
 }
Beispiel #2
0
 /**
  * Check if to use a mobile theme
  *
  * @return boolean
  */
 public function isMobileTheme()
 {
     if (is_bool($this->isMobileTheme)) {
         return $this->isMobileTheme;
     }
     if (!env('APP_MOBILE_THEME', false)) {
         return false;
     }
     /**
      * check if really a mobile
      * check cookie
      * check session
      * check user theme to use
      */
     if (env('APP_ENV_MOBILE', false)) {
         return true;
     }
     if ($this->detector()->isMobile()) {
         $this->isMobileTheme = true;
         return true;
     }
     if ($this->detector()->isTablet()) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_cookie($this->mobileVarName))) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_session_has($this->mobileVarName)) && !empty(zbase_session_get($this->mobileVarName))) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_request_query_input($this->mobileVarName))) {
         if (!empty(zbase_request_query_input($this->mobileVarName . 'Cookie'))) {
             zbase_cookie_forever($this->mobileVarName, 1);
         }
         $this->isMobileTheme = true;
         return true;
     }
     $this->isMobileTheme = false;
     return false;
 }
 public function watermark()
 {
     $folder = zbase_storage_path() . '/zivsluck/site/images/';
     $filename = str_replace('.png', '', zbase_route_input('f', false));
     $download = zbase_request_query_input('d', false);
     if (!empty($download)) {
         if (file_exists($folder . $filename . '.png')) {
             $w = new \Zivsluck\Models\Image();
             $w->watermark($folder . $filename . '.png');
             $w->download();
         }
     } else {
         if (file_exists($folder . $filename . '.png')) {
             $w = new \Zivsluck\Models\Image();
             $w->watermark($folder . $filename . '.png');
             $w->serve();
         }
     }
 }
Beispiel #4
0
 /**
  * Return the Current Page
  */
 public function getCurrentPage()
 {
     $sorting = zbase_request_query_input('page');
     if (!empty($sorting)) {
         return $sorting;
     }
     return 1;
 }
Beispiel #5
0
 /**
  *
  * @see $this->debug
  */
 public function getDebug()
 {
     if (zbase_request_query_input('__debug', false)) {
         return true;
     }
     return $this->debug;
 }
<?php

$perPages = $ui->getRowsPerPages();
if ($paginator instanceof \Illuminate\Pagination\LengthAwarePaginator) {
    $perPageRequest = zbase_request_query_input('pp', false);
    if (!empty($perPageRequest) && !zbase_is_angular()) {
        $paginator->appends(['pp' => $perPageRequest]);
    }
    $presenter = new \Illuminate\Pagination\BootstrapThreePresenter($paginator);
    if (zbase_is_angular()) {
        echo str_replace(array('?page=', 'class="pagination', route('index')), array('/page/', 'class="pagination pagination-pages pagination-sm', '#'), $presenter->render());
    } else {
        echo str_replace(array('class="pagination'), array('class="pagination pagination-pages pagination-sm'), $presenter->render());
    }
    if (!zbase_is_angular()) {
        echo '<ul class="pagination pagination-perpage pagination-sm">';
        if ($paginator->lastPage() > 1 && !empty($perPages)) {
            echo '<li><a class="btn disabled" href="#">Rows</a></li>';
        }
        if (!empty($perPages)) {
            foreach ($perPages as $perPage) {
                if ($paginator->total() > $perPage) {
                    echo '<li><a data-perpage="' . $perPage . '" ' . 'href="' . zbase_url_from_current(['pp' => $perPage], false) . '" ' . ($paginator->perPage() == $perPage ? 'class="active"' : '') . '>' . $perPage . '</a>' . '</li>';
                }
            }
        }
        if ($paginator->total() > $paginator->perPage()) {
            echo '<li><a data-perpage="all" href="' . zbase_url_from_current(['pp' => $paginator->total()], false) . '" ' . ($paginator->perPage() > $perPageRequest ? 'class="pagination-view-all active"' : '') . ' title="View all rows">' . 'View all' . '</a></li>';
        }
        echo '</ul>';
    }
Beispiel #7
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;
}
Beispiel #8
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();
}
Beispiel #9
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;
 }
Beispiel #10
0
/**
 * Check if to serve angular template
 * or to use an angular template
 * @return booleaan
 */
function zbase_is_angular_template()
{
    return zbase_request_query_input('at', false);
}
Beispiel #11
0
/**
 * Upload a file
 * @param string $index The form Index
 * @param string $folder the Folder to save the new file
 * @param string $newFilename the new filename (just filename no folder)
 * @param string $encodingFormat The Format the file to be encoded. jpg, png
 * @param array $size The Size to encode [$width, $height], [$width, null]
 * @return string The Path to the new file
 */
function zbase_file_upload_image($index, $folder, $newFilename, $encodingFormat = 'jpg', $size = [])
{
    /**
    * Using angular flow.js
    * https://github.com/flowjs/flow-php-server
    *
     "flowChunkNumber" => "1"
     "flowChunkSize" => "1048576"
     "flowCurrentChunkSize" => "83167"
     "flowTotalSize" => "83167"
     "flowIdentifier" => "83167-Avatar2jpg"
     "flowFilename" => "Avatar2.jpg"
     "flowRelativePath" => "Avatar2.jpg"
     "flowTotalChunks" => "1"
    *
    */
    $tmpFolder = zbase_tmp_path();
    $newFile = $folder . str_replace(array('.png', '.jpg', '.gif', '.bmp', '.jpeg'), '.' . $encodingFormat, $newFilename);
    if (!empty(zbase_request_query_input('flowChunkNumber', false))) {
        if (\Flow\Basic::save($newFile, $tmpFolder)) {
            $im = \Image::make($newFile);
        } else {
            // zbase()->json()->setVariable('files', $_FILES);
            // zbase()->json()->setVariable('success', false);
            // zbase()->json()->setVariable('get', $_GET);
            // zbase()->json()->setVariable('post', $_POST);
            return zbase_abort(204);
        }
    }
    if (!empty($_FILES[$index]['tmp_name'])) {
        zbase_directory_check($folder, true);
        if (class_exists('\\Image')) {
            $im = \Image::make($_FILES[$index]['tmp_name']);
        } else {
            if (move_uploaded_file($_FILES[$index]['tmp_name'], $newFile)) {
                return $newFile;
            }
        }
    }
    if (!empty($im)) {
        if (!empty($size)) {
            $im->resize($size[0], $size[1], function ($constraint) {
                $constraint->aspectRatio();
            });
        }
        $im->encode($encodingFormat, 100)->save($newFile);
        return $newFile;
    }
    return false;
}