/** * Controller Action * This will be called validating the form * @param string $action */ public function controller($action) { $this->_action = $action; if (empty($this->_entity()) && $this->isEntityNeeded()) { return zbase_abort(404); } }
/** * HTML the ui * @return string */ public function __toString() { $this->prepare(); try { if (!is_null($this->_viewFile) && empty($this->_rendered)) { $this->_viewParams['ui'] = $this; $str = $this->htmlPreContent(); $str .= zbase_view_render(zbase_view_file_contents($this->_viewFile), $this->getViewParams()); $str .= $this->htmlPostContent(); $this->_rendered = true; return $str; } return ''; } catch (\Exception $e) { if (zbase_is_dev()) { dd($e); } zbase_abort(500); } }
/** * Prepare and fetch all rows */ protected function _rows() { if (empty($this->_rowsPrepared)) { try { if (!empty($this->_entity)) { $repo = $this->_repo(); $repoMethod = $this->_v('repo.method', 'count'); if ($repoMethod == 'count') { if ($this->_entity->hasSoftDelete()) { $this->_rows = $repo->withTrashed()->count($this->_repoFilters, $this->_repoJoins); } else { $this->_rows = $repo->count($this->_repoFilters, $this->_repoJoins); } } } $this->_rowsPrepared = true; } catch (\Zbase\Exceptions\RuntimeException $e) { if (zbase_in_dev($e)) { dd($e); } else { zbase_abort(500); } } } }
$profile = zbase_config_get('modules.account.widgets.profile.enable', true); $image = zbase_config_get('modules.account.widgets.image.enable', true); $email = zbase_config_get('modules.account.widgets.email.enable', true); $username = zbase_config_get('modules.account.widgets.username.enable', true); $password = zbase_config_get('modules.account.widgets.password.enable', true); $notification = zbase_config_get('modules.account.widgets.notifications.enable', true); $currentUser = zbase_auth_user(); $moduleName = 'account'; $isAdmin = $currentUser->isAdmin(); $adminView = false; if ($isAdmin && !empty(zbase_route_input('id'))) { $adminView = true; $moduleName = 'admin-user'; $selectedUser = zbase_user_byid(zbase_route_input('id')); if (!$selectedUser instanceof \Zbase\Entity\Laravel\User\User) { zbase_abort(404); exit; } $page = []; $page['title'] = '<span class="userDisplayName' . $selectedUser->id() . '">' . $selectedUser->roleTitle() . ' - ' . $selectedUser->id() . ': ' . $selectedUser->displayName() . '</span>' . $selectedUser->statusText(); $page['headTitle'] = $selectedUser->displayName(); $page['subTitle'] = $selectedUser->email() . '|' . $selectedUser->username() . '|' . $selectedUser->cityStateCountry(); zbase_view_page_details(['page' => $page]); $breadcrumbs = [['label' => 'Users', 'route' => ['name' => 'admin.users']], ['label' => '<span class="userDisplayName' . $selectedUser->id() . '">' . $selectedUser->displayName() . '</span>', 'link' => '#', 'title' => $selectedUser->displayName()]]; zbase_view_breadcrumb($breadcrumbs); } else { $selectedUser = zbase_auth_user(); } $accountTabs = []; $accountContents = []; $accountContents[] = ['position' => 10, 'groupId' => 'information', 'content' => function () use($selectedUser) {
/** * Controller Action * This will be called validating the form * @param string $action */ public function controller($action) { if (!$this->checkUrlRequest()) { return zbase_abort(404); } $this->_rows(); $this->_actions(); $this->_columns(); if ($this->isExporting()) { return $this->export(); } }
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)); } }
/** * Upload a file for this node * @param string $index The Upload file name/index or the URL to file to download and save * @return void */ public function uploadNodeFile($index = 'file') { try { $defaultImageFormat = zbase_config_get('node.files.image.format', 'png'); $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '/' . $this->id() . '/'; zbase_directory_check($folder, true); $nodeFileObject = zbase_entity(static::$nodeNamePrefix . '_files', [], true); $nodeFiles = $this->files()->get(); if (preg_match('/http\\:/', $index) || preg_match('/https\\:/', $index)) { // File given is a URL if ($nodeFileObject->isUrlToFile()) { $filename = zbase_file_name_from_file(basename($index), time(), true); $uploadedFile = zbase_file_download_from_url($index, $folder . $filename); } else { $nodeFiles = $this->files()->get(); $nodeFileObject->is_primary = empty($nodeFiles) ? 1 : 0; $nodeFileObject->status = 2; $nodeFileObject->mimetype = null; $nodeFileObject->size = null; $nodeFileObject->filename = null; $nodeFileObject->url = $index; $nodeFileObject->node_id = $this->id(); $nodeFileObject->save(); $this->files()->save($nodeFileObject); return $nodeFileObject; } } if (zbase_file_exists($index)) { $uploadedFile = $index; $filename = basename($index); } if (!empty($_FILES[$index]['name'])) { $filename = zbase_file_name_from_file($_FILES[$index]['name'], time(), true); $uploadedFile = zbase_file_upload_image($index, $folder, $filename, $defaultImageFormat); } if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) { $nodeFileObject->is_primary = empty($nodeFiles) ? 1 : 0; $nodeFileObject->status = 2; $nodeFileObject->mimetype = zbase_file_mime_type($uploadedFile); $nodeFileObject->size = zbase_file_size($uploadedFile); $nodeFileObject->filename = basename($uploadedFile); $nodeFileObject->node_id = $this->id(); $nodeFileObject->save(); $this->files()->save($nodeFileObject); return $nodeFileObject; } } catch (\Zbase\Exceptions\RuntimeException $e) { if (zbase_is_dev()) { dd($e); } zbase_abort(500); } }
}, '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); }]]];
/** * 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); } }
/** * Throw an exception */ function zbase_exception_throw(\Exception $e) { if (zbase_is_dev()) { throw new \Exception($e); dd($e); } zbase_alert('error', 'There was a problem. ' . $e->getMessage()); zbase_abort(500); }
/** * REsize the File * @param type $file * @param type $w * @param type $h * @param type $q */ public function postFileResize($path, $width, $height, $q = 80) { if (!class_exists('\\Image')) { $image = zbase_file_serve_image($path, $width, $height, $q); if (!empty($image)) { header('Content-type: ' . $image['mime']); return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime'])); } return zbase_abort(404); } return \Image::cache(function ($image) use($width, $height, $path) { if (empty($width)) { $size = getimagesize($path); $width = $size[0]; $height = $size[1]; } if (!empty($width) && !empty($height)) { return $image->make($path)->resize($width, $height, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); } if (!empty($width) && empty($height)) { return $image->make($path)->resize($width, null, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); } if (empty($width) && !empty($height)) { return $image->make($path)->resize(null, $height, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); } return $image->make($path)->resize($width, $height); }); }
/** * Serve the File * @param integer $width * @param integer $height * @param integer $quality Image Quality * @param boolean $download If to download * @return boolean */ public function serveImage($width, $height = null, $quality = null, $download = false, $image = null) { $folder = zbase_storage_path() . '/' . zbase_tag() . '/user/' . $this->id() . '/'; if (!empty($image)) { $path = $folder . $image; } else { $path = $folder . $this->avatar; } if (!class_exists('\\Image')) { $image = zbase_file_serve_image($path, $width, $height, $quality, $download); if (!empty($image)) { return \Response::make(readfile($image['src'], $image['size'])->header('Content-Type', $image['mime'])); } return zbase_abort(404); } // dd($this, $path, file_exists($path)); if (file_exists($path)) { $cachedImage = \Image::cache(function ($image) use($width, $height, $path) { if (empty($width)) { $size = getimagesize($path); $width = $size[0]; $height = $size[1]; } if (!empty($width) && empty($height)) { return $image->make($path)->resize($width, null, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); } if (empty($width) && !empty($height)) { return $image->make($path)->resize(null, $height, function ($constraint) { $constraint->upsize(); $constraint->aspectRatio(); }); } return $image->make($path)->resize($width, $height); }); return \Response::make($cachedImage, 200, array('Content-Type' => 'image/png')); } return false; }
/** * 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; }
/** * 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; }
/** * Create a route * @param string $name The Route Name * @param array $route The Route configuration * @return Response */ function zbase_route_response($name, $route) { if (!empty(zbase_is_maintenance())) { return zbase_response(view(zbase_view_file('maintenance'))); } $redirect = zbase_value_get($route, 'redirect', false); if (!empty($redirect)) { return redirect()->to($redirect); } $response = zbase_value_get($route, 'response', false); if (!empty($response)) { return $response; } /** * If we are using username in routes, * we have to check if the username exists in DB. * This is checked in zbase_route_username_get() * if the zbase_route_username_get() returns false, means * that the route is not a username or username didn't exists. * Here we check against all other Routes if the prefix is in our * list of routes, if not found, throw NotFoundHttpException */ $useUsernameRoute = zbase_route_username(); $usernameRoute = zbase_route_username_get(); $usernameRouteCheck = zbase_data_get($route, 'usernameRouteCheck', true); if (empty($usernameRouteCheck)) { /** * Will not check for username route */ $useUsernameRoute = false; } //if($usernameRoute === false && !empty($useUsernameRoute)) if ($name == 'index' && zbase_auth_has() && !empty($useUsernameRoute)) { return redirect()->to('/' . zbase_auth_real()->username); } if ($usernameRoute === false && !empty($useUsernameRoute)) { $uri = zbase_url_uri(); $adminKey = zbase_admin_key(); if (!empty($uri)) { $uriEx = explode('/', $uri); if (!empty($uriEx)) { foreach ($uriEx as $uriV) { if (!empty($uriV)) { /** * If it isn't an admin key, check it against given Routes */ if ($uriV !== $adminKey) { $routes = zbase_config_get('routes', []); if (!empty($routes)) { foreach ($routes as $rName => $r) { if (!empty($r['enable']) && !empty($r['url'])) { $urlEx = explode('/', $r['url']); if (!empty($urlEx)) { foreach ($urlEx as $urlExV) { if (!empty($urlExV)) { if ($uriV == $urlExV) { /** * Found it, valid URL */ $validUrlPrefix = true; } /** * Will deal only with the first not empty value so break it. */ break; } } } } if (!empty($validUrlPrefix)) { /** * Found it, break it */ $name = $rName; $route = $r; break; } } } } else { return redirect(zbase_url_from_route('home')); } /** * Will deal only with the first not empty value so break it. */ break; } } if (empty($validUrlPrefix)) { /** * Only if routeName is not the index */ if ($name != 'index') { // $response = new \Zbase\Exceptions\NotFoundHttpException(); // return $response->render(zbase_request(), $response); } } } } } $usernameRoutePrefix = zbase_route_username_prefix(); $originalRouteName = str_replace($usernameRoutePrefix, '', $name); zbase()->setCurrentRouteName($name); $guest = true; $authed = false; $guestOnly = false; $middleware = !empty($route['middleware']) ? $route['middleware'] : false; $backend = !empty($route['backend']) ? $route['backend'] : false; if ($name == 'password-reset' && zbase_auth_has()) { \Auth::guard()->logout(); return redirect(zbase_url_from_current()); } if (!empty($backend)) { // zbase_in_back(); } if (preg_match('/\\?usernameroute/', zbase_url_uri()) > 0 && !empty($useUsernameRoute) && zbase_auth_has()) { return redirect()->to('/' . zbase_auth_user()->username() . '/home'); } if (!empty($useUsernameRoute) && zbase_auth_has() && $usernameRoute != zbase_auth_user()->username()) { return redirect(zbase_url_from_route($originalRouteName, [$usernameRoutePrefix => zbase_auth_user()->username()])); } if (!empty($middleware)) { if (is_array($middleware)) { $access = isset($middleware['access']) ? $middleware['access'] : false; if (!empty($access) && is_array($access)) { if (!zbase_auth_has()) { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect(zbase_url_from_route('login')); } if (zbase_auth_has() && !zbase_auth_is($access)) { return zbase_abort(401, ucfirst($access) . ' is needed to access the page.'); } } else { $guest = isset($middleware['guest']) ? $middleware['guest'] : false; $authed = isset($middleware['auth']) ? $middleware['auth'] : false; $adminAuthed = isset($middleware['admin']) ? $middleware['admin'] : false; if ($adminAuthed) { $authed = true; } $guestOnly = isset($middleware['guestOnly']) ? $middleware['guestOnly'] : false; } } } if (empty($access)) { if (!empty($backend)) { if (!empty($usernameRoute)) { /** * If user is loggedIn and this is admin side and this is not logIn page, * redirect to users dashboard. * User can only access his own dashboard via /{usernameroute?}/admin */ if (zbase_auth_has() && zbase_auth_is(zbase_route_username_minimum_access()) && zbase_is_back() && $usernameRoute != zbase_auth_user()->username()) { return redirect(zbase_url_from_route('admin', [$usernameRoutePrefix => zbase_auth_user()->username])); } if ((empty(zbase_auth_has()) || !zbase_auth_is('user')) && $name != $usernameRoutePrefix . 'admin.login') { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect(zbase_url_from_route('admin.login')); } } else { if ((empty(zbase_auth_has()) || !zbase_auth_is('admin')) && $name != 'admin.login') { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect(zbase_url_from_route('admin.login')); } } } else { if (!empty($guestOnly) && zbase_auth_has()) { return redirect(zbase_url_from_route('home')); } if (!empty($usernameRoute)) { if (!empty($authed) && !zbase_auth_has() && $name != $usernameRoutePrefix . 'login') { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect(zbase_url_from_route('login')); } } else { if (!empty($authed) && !zbase_auth_has() && $name != 'login') { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect(zbase_url_from_route('login')); } } } } $params = zbase_route_inputs(); $requestMethod = zbase_request_method(); $controller = !empty($route['controller']) ? $route['controller'] : null; $command = !empty($route['command']) ? $route['command'] : false; if (!empty($command) && $command instanceof \Closure) { $command(); exit; } if (!empty($controller) && !empty($controller['name']) && !empty($route['controller']['enable'])) { $controllerName = !empty($route['controller']['name']) ? $route['controller']['name'] : null; $controllerMethod = !empty($route['controller']['method'][$requestMethod]) ? $route['controller']['method'][$requestMethod] : (!empty($route['controller']['method']) ? $route['controller']['method'] : 'index'); if (!empty($controllerName)) { $controllerConfig = zbase_config_get('controller.class.' . $controllerName, null); if (!empty($controllerConfig) && !empty($controllerConfig['enable'])) { $controllerClass = zbase_controller_create_name(zbase_config_get('controller.class.' . $controllerName . '.name', Zbase\Http\Controllers\__FRAMEWORK__\PageController::class)); $controllerObject = zbase_object_factory($controllerClass, !empty($route['controller']['params']) ? $route['controller']['params'] : []); zbase()->setController($controllerObject->setName($controllerName)->setActionName($controllerMethod)->setRouteParameters($params)); zbase_view_page_details($route); return zbase_response($controllerObject->{$controllerMethod}()); } } } $view = !empty($route['view']) ? $route['view'] : null; if (!empty($view) && !empty($view['name']) && !empty($route['view']['enable'])) { zbase_view_page_details($route); if (!empty($route['view']['content'])) { $params['content'] = zbase_data_get($route['view']['content'], null); } if ($view['name'] == 'type.js') { zbase_response_format_set('javascript'); } return zbase_response(zbase_view_render(zbase_view_file($view['name']), $params)); } }
/** * Upload a file for this node * @param string $index The Upload file name/index or the URL to file to download and save * @return void */ public function uploadNodeFile($index = 'file') { try { $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '_category' . '/' . $this->id() . '/'; zbase_directory_check($folder, true); if (!empty($_FILES[$index]['name'])) { $filename = $this->alphaId(); //zbase_file_name_from_file($_FILES[$index]['name'], time(), true); $uploadedFile = zbase_file_upload_image($index, $folder, $filename, zbase_config_get('node.files.image.format', 'png')); } if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) { $filename = basename($uploadedFile); $this->setDataOption('avatar', $filename); $this->save(); } } catch (\Zbase\Exceptions\RuntimeException $e) { if (zbase_is_dev()) { dd($e); } zbase_abort(500); } }
/** * Create new Message * @param string $message The MEssage * @param string $subject Subject * @param string $sender UserId or User objcet * @param string $recipient UserId or User objeect * @param array $options * @return \Zbase\Entity\Laravel\Message\Message */ public function newMessage($message, $subject, $sender, $recipient, $options) { try { $this->subject = $subject; $this->content = $message; if (!empty($options['parent_id'])) { $this->parent_id = $options['parent_id']; } if (!empty($options['node_id'])) { $this->node_id = $options['node_id']; } if (!empty($options['node_prefix'])) { $this->node_prefix = $options['node_prefix']; } if (!$sender instanceof \Zbase\Entity\Laravel\User\User && is_numeric($sender)) { $sender = zbase_user_byid($sender); } if ($sender instanceof \Zbase\Entity\Laravel\User\User) { $this->sender_id = $sender->id(); } $this->save(); // For the Recipient $this->_msgRecipient($recipient); $this->_msgSender($sender); return $this; } catch (\Zbase\Exceptions\RuntimeException $e) { if (zbase_is_dev()) { dd($e); } zbase_abort(503); } }
/** * Validate widget */ public function validateWidget($action) { if ($this->_urlHasRequest) { if (empty($this->_entity)) { return zbase_abort(404); } if ($this->isAdmin() && $this->_entity instanceof \Zbase\Entity\Laravel\Node\Nested) { $children = $this->_entity->getImmediateDescendants(); if ($children->count()) { return zbase_abort(404); } } } $this->setAction($action); $this->prepare(); if (zbase_request_method() == 'post') { $currentTab = zbase_request_input('tab', false); if (!empty($currentTab)) { zbase_session_flash('sessiontab', $currentTab); } if ($this->isDeleting()) { return; } $validationRules = $this->getValidationRules(); if (!empty($validationRules)) { $v = \Validator::make(zbase_request_inputs(), $validationRules, $this->getValidationMessages()); if ($v->fails()) { zbase_session_flash('posted', true); $this->setHasError($v->errors()->getMessages()); $messageBag = $v->getMessageBag(); zbase_alert(\Zbase\Zbase::ALERT_ERROR, $messageBag, ['formvalidation' => true]); return $v; } $inputs = zbase_request_inputs(); foreach ($inputs as $k => $v) { $e = $this->element($k); if ($e instanceof \Zbase\Ui\Form\ElementInterface) { $e->setValue($v); } } } } }
public function create($text, $font = null, $material = null, $options = null) { if (!empty($text)) { $this->setText($text); } if (!empty($font)) { $this->setFont($font); } if (!$this->orderData instanceof \Zivsluck\Entity\Laravel\Order && !empty($options['oid'])) { $orderData = zbase_entity('custom_orders')->repository()->byId($options['oid']); if (empty($orderData)) { return zbase_abort(404); } $this->setOrderData($orderData); } $tags = []; $dealerCopy = !empty($options['dealerCopy']) ? true : false; /** * <span id="IL_AD8" class="IL_AD">Setup</span> some custom variables for creating our font and image. */ $chain = !empty($options['chain']) ? $options['chain'] : false; $chainLength = !empty($options['chainLength']) ? $options['chainLength'] : false; $maxLetter = 7; $pricePerLetter = 20; $boxWidth = 280; $boxHeight = 200; $brandingHeightPosition = 200; $borderWidth = 10; $hasBorder = !empty($dealerCopy) ? true : false; $hasDetails = false; $fontsNotForMaterial = zbase_config_get('zivsluck.chains.' . $material . '.fonts.not', []); $fontNotForMaterial = false; $posYDiff = 0; if (!empty($fontsNotForMaterial)) { if (in_array($font, $fontsNotForMaterial)) { $fontNotForMaterial = true; } } if (!empty($chain) && !empty($chainLength)) { $hasDetails = true; $boxWidth = 280; $boxHeight = 600; $brandingHeightPosition = 600; $chainFile = zbase_config_get('zivsluck.chains.' . strtolower($material) . '.' . strtolower($chain) . '.file', false); $chainImage = zbase_public_path() . '/zbase/assets/zivsluck/img/chain/' . $chainFile; $tags[] = $chain; } $letterPrice = 0; $shippingFee = 0; $hasShipping = false; $total = 0; $courier = !empty($options['courier']) ? $options['courier'] : false; if (!empty($courier)) { $courier = zbase_config_get('zivsluck.shipping.' . strtolower($courier), false); if (!empty($courier)) { $deliveryMode = !empty($options['deliveryMode']) ? $options['deliveryMode'] : false; $hasShipping = true; $courierName = $courier['name']; if ($deliveryMode == 'meetup') { $courierText = 'Meet Up'; $shippingFee = 0.0; } else { $shippingFee = $courier['fee']; $courierText = $courierName . ' - ' . ($deliveryMode == 'doortodoor' ? 'Door-to-Door' : 'PickUp'); } $boxWidth = 280; $boxHeight = 800; $brandingHeightPosition = 800; } if (empty($options['shippingSame'])) { $options['shippingFirstName'] = $options['first_name']; $options['shippingLastName'] = $options['last_name']; } } $customerNote = !empty($options['customerNote']) ? $options['customerNote'] : ''; $orderData = $this->getOrderData(); $statusNew = false; $statusPaid = false; if (!empty($orderData)) { $statusPaid = $orderData->status == 2; if (!empty($options['download']) && $orderData->status == 1) { $boxWidth = 280; $boxHeight = 800 + 380; $posYDiff = 190; $brandingHeightPosition = 800; $statusNew = true; } if (!empty($statusPaid)) { $paymentCenterName = zbase_config_get('zivsluck.paymentCenters.' . $orderData->payment_merchant . '.shortName'); $paymentAmount = $orderData->total; if (file_exists(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png')) { $paymentDetailsIm = imagecreatefrompng(zbase_storage_path() . '/zivsluck/order/receipts/' . $orderData->maskedId() . '.png'); $boxHeight = $boxHeight + imagesy($paymentDetailsIm); $posYDiff = imagesy($paymentDetailsIm) / 2; $brandingHeightPosition = 800; } } } $price = zbase_config_get('zivsluck.price.' . $material, false); $fontSize = 30; // font size $chars = 30; $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/deftonestylus.ttf'; // the text file to be used $verdanaFont = zbase_public_path() . '/zbase/assets/zivsluck/fonts/verdana.ttf'; // the text file to be used $textureFile = zivsluck()->path() . 'resources/assets/img/texture/' . strtolower($material) . '.png'; // the texture file $logo = zivsluck()->path() . 'resources/assets/img/texture/logo.png'; // the texture file $paymentDetails = zivsluck()->path() . 'resources/assets/img/payments/bayadCenter.png'; // the texture file $fontDetails = $this->getFontDetails(); $tags[] = $material; $tags[] = $font; if (!empty($dealerCopy)) { $boxWidth = 280; $boxHeight = 500; $brandingHeightPosition = 500; $posYDiff = 0; } /** * Get text string that is <span id="IL_AD7" class="IL_AD">passed</span> to this file and clean it up. */ $text = $this->getText(); $text = trim(strip_tags(html_entity_decode($text))); // $text = trim(preg_replace('/ss+/', ' ', $text)); $text = strlen($text) > $chars ? substr($text, 0, $chars) . '..' : $text; if (!empty($fontDetails['enable'])) { $fontFile = zbase_public_path() . '/zbase/assets/zivsluck/fonts/' . $fontDetails['file']; if (!empty($fontDetails['fontsize'])) { $fontSize = $fontDetails['fontsize']; } } else { $fontFile = $verdanaFont; $text = 'FONT NOT AVAILABLE.'; } if ($fontNotForMaterial) { $fontFile = $verdanaFont; $fontSize = 14; // font size $text = wordwrap("ERROR: \nFONT NOT FOR " . strtoupper($material) . ". \nSelect another font.", 20); $hasDetails = false; $boxWidth = 280; $boxHeight = 200; $brandingHeightPosition = 200; } // <editor-fold defaultstate="collapsed" desc="Image Printin"> /** * Read the TTF file and get the width and height of our font. */ $box = imagettfbbox($fontSize, 0, $fontFile, $text); $width = abs($box[2] - $box[0]) + 50; /** * Create <span id="IL_AD2" class="IL_AD">the blank</span> image, alpha channel and colors. */ // http://stackoverflow.com/questions/26288347/php-gd-complex-stacking-multiple-layers // $clipart = imagecreatefrompng(zivsluck()->path() . 'resources/assets/img/createBaseImage.png'); $bgTexture = imagecreatefrompng($textureFile); $noBg = !empty(zbase_cookie('nobg')) ? true : false; $logo = imagecreatefrompng($logo); $white = imagecolorallocate($bgTexture, 255, 255, 255); if ($dealerCopy) { // Canvass $bgTexture = imagecreatetruecolor($boxWidth - $borderWidth * 2, $boxHeight - $borderWidth * 2); // Background Color $white = imagecolorallocate($bgTexture, 255, 255, 255); } if (!empty($noBg)) { $bgTexture = imagecreatetruecolor($boxWidth, $boxHeight); } /** * Create text on a white background */ imagefill($bgTexture, 0, 0, $white); $textColorBlack = imagecolorallocate($bgTexture, 0, 0, 0); if (empty($posY)) { if ($hasDetails) { if ($hasShipping) { $posY = $boxHeight / 2 + 10 - 300 - $posYDiff; } else { $posY = $boxHeight / 2 + 10 - 200 - $posYDiff; } } else { $posY = $boxHeight / 2 + 10 - $posYDiff; } $posX = $boxWidth / 2 - $width / 2 + 10; if (!empty($hasBorder)) { $posY = $boxHeight / 2 + 10 - 150 - $borderWidth - $posYDiff; $posX = $boxWidth / 2 - $width / 2; } } if ($fontNotForMaterial) { imagettftext($bgTexture, $fontSize, 0, $posX, 60, $textColorBlack, $fontFile, $text); } else { imagettftext($bgTexture, $fontSize, 0, $posX, $posY, $textColorBlack, $fontFile, $text); } $im = imagecreatetruecolor($boxWidth, $boxHeight); if (!empty($dealerCopy)) { imagecopy($im, $bgTexture, $borderWidth, $borderWidth, 0, 0, $boxWidth, $boxHeight); } else { imagecopy($im, $bgTexture, 0, 0, 0, 0, $boxWidth, $boxHeight); } $img = imagecreatetruecolor($boxWidth, $boxHeight); imagecopymerge($img, $im, 0, 0, 0, 0, $boxWidth, $boxHeight, 100); if ($hasBorder) { imagecopy($img, $logo, 234, $brandingHeightPosition - 45, 0, 0, imagesx($logo), imagesy($logo)); } else { imagecopy($img, $logo, 245, $brandingHeightPosition - 35, 0, 0, $boxWidth, $boxHeight); } if (!empty($dealerCopy)) { // Add border imagefilltoborder($img, 1, 1, $textColorBlack, $white); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="ADDON"> $totalAddon = 0; if (!empty($options['addon'])) { $addonDroppableTop = zbase_config_get('zivsluck.addons.configuration.droppable.top') - 5; $addonDroppableLeft = zbase_config_get('zivsluck.addons.configuration.droppable.left') - 5; $addonDroppableHeight = zbase_config_get('zivsluck.addons.configuration.droppable.height'); $addonDroppableWidth = zbase_config_get('zivsluck.addons.configuration.droppable.width'); $addons = explode('|', $options['addon']); $includedAddons = []; foreach ($addons as $addon) { if (!empty($addon)) { // $addon = explode('-', $addon); // $addonName = !empty($addon[0]) ? $addon[0] : false; // $addonEnabled = zbase_config_get('zivsluck.addons.' . $addonName . '.enable'); // $addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . zbase_config_get('zivsluck.addons.' . $addonName . '.file'); // $addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false; // $addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false; // $addonRotate = intval(!empty($addon[3]) ? $addon[3] : false); $addon = explode('-', $addon); $addonName = !empty($addon[0]) ? $addon[0] : false; $addonEnabled = true; //zbase_config_get('zivsluck.addons.' . $addonName . '.enable'); $addonFile = zivsluck()->path() . 'resources/assets/img/addons/' . $addonName . '.png'; $addonPosition = !empty($addon[1]) ? explode(',', $addon[1]) : false; $addonSize = !empty($addon[2]) ? explode('x', $addon[2]) : false; $addonRotate = intval(!empty($addon[3]) ? $addon[3] : false); if (!empty($addonEnabled) && file_exists($addonFile)) { if (!in_array($addonName, $tags)) { $tags[] = $addonName; } $includedAddons[] = $addonName; $addonNewImage = imagecreatetruecolor($addonSize[0], $addonSize[1]); $transparent = imagecolorallocatealpha($addonNewImage, 0, 0, 0, 127); $addonFile = imagecreatefrompng($addonFile); if (!empty($addonRotate)) { $addonFile = imagerotate($addonFile, 360 - $addonRotate, imageColorAllocateAlpha($addonFile, 0, 0, 0, 127)); } if (empty($addonSize[0])) { $addonSize[0] = imagesx($addonFile); } if (empty($addonSize[1])) { $addonSize[1] = imagesy($addonFile); } imagefill($addonNewImage, 0, 0, $transparent); imagecopyresampled($addonNewImage, $addonFile, 0, 0, 0, 0, $addonSize[0], $addonSize[1], imagesx($addonFile), imagesy($addonFile)); $totalAddon++; imagecopy($img, $addonNewImage, $addonPosition[0] + $addonDroppableLeft, $addonPosition[1] + $addonDroppableTop, 0, 0, $addonSize[0], $addonSize[1]); } } } } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Checkout Details"> if ($hasDetails) { // <editor-fold defaultstate="collapsed" desc="DISCOUNT"> $discountInPrice = zbase_config_get('zivsluck.promotion.discount', 0.0); if (!empty($orderData) && !empty($options['final'])) { $promo = !empty($options['promo_flag']) ? true : false; if (!empty($promo)) { $discountInPrice = $options['promo_discountprice']; $shippingFee = $options['promo_shipping_fee']; $associateOrderId = $options['promo_associate_order_id']; } else { if (!empty($options['promo_associate_order_id'])) { $associateOrderId = $options['promo_associate_order_id']; } } } else { $promo = $this->_discountOnNextOrder($text, $font, $material, $options); $options['promo_flag'] = 0; if (!empty($promo)) { $promoOrder = $promo; $promo = true; $options['promo_flag'] = 1; $shippingFee = 0.0; $options['promo_discountprice'] = $discountInPrice; $options['promo_shipping_fee'] = $shippingFee; $options['promo_associate_order_id'] = $promoOrder->id(); $associateOrderId = $promoOrder->id(); } } // </editor-fold> if (empty($dealerCopy)) { $chainImage = imagecreatefrompng($chainImage); $total = $price; $subTotal = $price; $letterCount = strlen($text); $addonPrice = 0; $totalCharacters = $letterCount + $totalAddon; if ($totalCharacters > $maxLetter) { if ($letterCount > $maxLetter) { if (!empty($totalAddon)) { $addonCount = $letterCount + $totalAddon - $maxLetter; $addonPrice = $addonCount * 20; $total += $addonPrice; $subTotal += $addonPrice; } } else { $totalAddon = $totalCharacters - $maxLetter; $addonPrice = $totalAddon * 20; } } // if($letterCount < $maxLetter) // { // if(!empty($totalAddon)) // { // $addonCount = ($letterCount + $totalAddon) - $maxLetter; // $addonPrice = $addonCount * 20; // $total += $addonPrice; // $subTotal += $addonPrice; // } // } // if($letterCount > $maxLetter) // { // $letterPrice = ($letterCount - $maxLetter) * 20; // $total += $letterPrice; // $addonPrice = $totalAddon * 20; // $total += $addonPrice; // $subTotal += $addonPrice; // } $total += $shippingFee; if (!empty($promo)) { $total -= $discountInPrice; } if (!empty($orderData)) { imagettftext($img, 12, 0, 15, 180, $textColorBlack, $verdanaFont, 'ORDER ID: ' . $orderData->maskedId()); } imagecopy($img, $chainImage, 15, 295, 0, 0, imagesx($chainImage), imagesy($chainImage)); } if (!empty($dealerCopy)) { imagettftext($img, 9, 0, 25, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text); imagettftext($img, 9, 0, 25, 220, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']); imagettftext($img, 9, 0, 25, 240, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material)); imagettftext($img, 9, 0, 25, 260, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain)); imagettftext($img, 9, 0, 25, 280, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"'); if (!empty($includedAddons)) { imagettftext($img, 8, 0, 25, 300, $textColorBlack, $verdanaFont, 'Included Addons:'); imagettftext($img, 8, 0, 25, 320, $textColorBlack, $verdanaFont, wordwrap(implode(', ', $includedAddons), 30)); } if (!empty($customerNote)) { imagettftext($img, 9, 0, 25, 360, $textColorBlack, $verdanaFont, 'Customer Note:'); imagettftext($img, 8, 0, 25, 380, $textColorBlack, $verdanaFont, wordwrap($customerNote, 40)); } } else { imagettftext($img, 9, 0, 15, 200, $textColorBlack, $verdanaFont, 'Text: ' . $text); imagettftext($img, 9, 0, 15, 215, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']); imagettftext($img, 9, 0, 15, 230, $textColorBlack, $verdanaFont, 'Character: ' . strlen($text)); imagettftext($img, 9, 0, 15, 245, $textColorBlack, $verdanaFont, 'Symbols: ' . $totalAddon); imagettftext($img, 9, 0, 15, 260, $textColorBlack, $verdanaFont, 'Material: ' . ucfirst($material)); imagettftext($img, 9, 0, 15, 275, $textColorBlack, $verdanaFont, 'Chain Length: ' . $chainLength . '"'); imagettftext($img, 9, 0, 15, 290, $textColorBlack, $verdanaFont, 'Chain: ' . strtoupper($chain)); if (!empty($this->displayPrice)) { imagettftext($img, 9, 0, 15, 430, $textColorBlack, $verdanaFont, ucfirst($material) . ' Price: Php ' . number_format($price, 2)); imagettftext($img, 9, 0, 15, 445, $textColorBlack, $verdanaFont, 'Characters: Php ' . number_format($letterPrice, 2)); imagettftext($img, 9, 0, 15, 460, $textColorBlack, $verdanaFont, 'Symbols: Php ' . number_format($addonPrice, 2)); } if ($hasShipping) { imagettftext($img, 9, 0, 15, 475, $textColorBlack, $verdanaFont, 'Shipping: Php ' . number_format($shippingFee, 2)); imagettftext($img, 9, 0, 15, 490, $textColorBlack, $verdanaFont, 'Courier: ' . $courierText); if (!empty($promo)) { imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Discount: ' . number_format($discountInPrice, 2) . ' (Order#' . $associateOrderId . ')'); } else { if (!empty($associateOrderId)) { imagettftext($img, 9, 0, 15, 505, $textColorBlack, $verdanaFont, 'Associate Order Id: ' . $associateOrderId); } } imagettftext($img, 9, 0, 15, 580, $textColorBlack, $verdanaFont, 'Shipping Information:'); imagettftext($img, 9, 0, 15, 600, $textColorBlack, $verdanaFont, $options['shippingFirstName'] . ' ' . $options['shippingLastName']); imagettftext($img, 9, 0, 15, 615, $textColorBlack, $verdanaFont, $options['address']); imagettftext($img, 9, 0, 15, 630, $textColorBlack, $verdanaFont, $options['addressb']); imagettftext($img, 9, 0, 15, 645, $textColorBlack, $verdanaFont, $options['city']); imagettftext($img, 8, 0, 15, 665, $textColorBlack, $verdanaFont, 'Ordered By: ' . $options['first_name'] . ' ' . $options['last_name']); imagettftext($img, 8, 0, 15, 680, $textColorBlack, $verdanaFont, $options['fb']); imagettftext($img, 8, 0, 15, 695, $textColorBlack, $verdanaFont, 'Phone: ' . $options['phone']); if (!empty($options['email'])) { imagettftext($img, 8, 0, 15, 710, $textColorBlack, $verdanaFont, 'Email: ' . $options['email']); } if (!empty($options['oid'])) { imagettftext($img, 8, 0, 15, 748, $textColorBlack, $verdanaFont, 'Order Link: ' . zbase_url_create('order', array('id' => $options['oid']))); } imagettftext($img, 8, 0, 15, 760, $textColorBlack, $verdanaFont, 'Date: ' . date('F d, Y h:i A')); } if (!empty($this->displayPrice)) { imagettftext($img, 18, 0, 15, 540, $textColorBlack, $verdanaFont, 'Total: Php ' . number_format($total, 2)); } if (!empty($statusPaid)) { imagettftext($img, 9, 0, 15, 555, $textColorBlack, $verdanaFont, 'PAID ' . number_format($paymentAmount, 2) . ' via ' . $paymentCenterName . ' (' . $orderData->paid_date_at->format('m/d/Y') . ')'); } if (!empty($orderData) && $orderData->status == 1 && !empty($options['step']) && $options['step'] == 5) { $orderData->total = $total; $orderData->subtotal = $subTotal; $orderData->shipping_fee = $shippingFee; unset($options['step']); $options['final'] = 1; if (!empty($promoOrder)) { $orderData->promo_flag = 1; } $orderData->details = json_encode($options); if (!empty($tags)) { $orderData->tags = implode(', ', $tags); } $orderData->save(); if (!empty($promoOrder)) { $promoOrderDetails = (array) $promoOrder->details(); $promoOrderDetails['promo_associate_order_id'] = $orderData->id(); $promoOrder->details = json_encode($promoOrderDetails); $promoOrder->promo_flag = 1; $promoOrder->save(); } } } } else { imagettftext($img, 9, 0, 15, 23, $textColorBlack, $verdanaFont, 'Font: ' . $fontDetails['name']); } if (!empty($hasBorder)) { imagettftext($img, 7, 0, 15, $brandingHeightPosition - (10 + $borderWidth), $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com'); } else { imagettftext($img, 7, 0, 15, $brandingHeightPosition - 10, $textColorBlack, $verdanaFont, 'Create your necklace at http://zivsluck.com'); } if (!empty($statusNew)) { $paymentDetailsIm = imagecreatefrompng($paymentDetails); imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight); } if (!empty($statusPaid) && empty($dealerCopy)) { if (!empty($paymentDetailsIm)) { imagecopy($img, $paymentDetailsIm, 0, 800, 0, 0, $boxWidth, $boxHeight); } } // </editor-fold> /** * Label */ $this->_image = $img; return $this; }
/** * Method not allowed * * @param string $msg * @return type */ public function methodNotAllowed($msg = 'Method not allowed.') { return zbase_abort(405, _zt($msg)); }