/** * @return void * @test * @group Ui */ public function testElementFactorySelect() { $element = ['type' => 'select', 'label' => 'Select Element Label', 'id' => 'elementId', 'multiOptions' => ['valueThree' => 'ValueCheckobx Label']]; $elementRoute = ['view' => ['name' => zbase_tag() . 'test::contents.test.content', 'enable' => true, 'content' => function () use($element) { return zbase_ui_form_element($element); }], 'url' => '/test/ui-form-element-select', 'enable' => true]; zbase_route_init('uiFormElementSelect', $elementRoute); $this->visit('/test/ui-form-element-select')->see('Select Element Label'); }
/** * @group Ui */ public function testTabs() { $tabOneConfiguration = ['type' => 'tab', 'label' => 'Tab One', 'id' => 'tabOne', 'group' => 'ExampleTab', 'position' => 100, 'contents' => [['id' => 'contentId', 'enable' => true, 'content' => 'The Content of Tab One'], ['id' => 'contentTwoId', 'enable' => true, 'content' => 'The Second Content of Tab One'], ['id' => 'contentThreeId', 'enable' => true, 'content' => 'The third Content of Tab One']]]; $tabTwoConfiguration = ['type' => 'tab', 'label' => 'Tab Two', 'id' => 'tabTwo', 'group' => 'ExampleTab', 'contents' => [['id' => 'contentId', 'enable' => true, 'content' => 'The Content of Tab Two'], ['id' => 'contentTwoId', 'enable' => true, 'content' => 'The Second Content of Tab Two'], ['id' => 'contentThreeId', 'enable' => true, 'content' => 'The third Content of Tab Two']]]; $tabThreeConfiguration = ['type' => 'tab', 'label' => 'Tab Three', 'id' => 'tabThree', 'group' => 'ExampleTab', 'contents' => [['id' => 'contentId', 'enable' => true, 'content' => 'The Content of Tab Three'], ['id' => 'contentTwoId', 'enable' => true, 'content' => 'The Second Content of Tab Three'], ['id' => 'contentThreeId', 'enable' => true, 'content' => 'The third Content of Tab Three']]]; $elementRoute = ['view' => ['name' => zbase_tag() . 'test::contents.test.content', 'enable' => true, 'content' => function () use($tabOneConfiguration, $tabTwoConfiguration, $tabThreeConfiguration) { return zbase_ui_tabs([$tabOneConfiguration, $tabTwoConfiguration, $tabThreeConfiguration]); }], 'url' => '/test/ui-tab', 'enable' => true]; zbase_route_init('uiTest', $elementRoute); $this->visit('/test/ui-tab')->see('<a data-toggle="tab" href="#ExampleTabtabOne">Tab One</a>'); }
/** * Execute the console command. * * @return mixed */ public function handle() { zbase()->setConsoleCommand($this); $phpCommand = env('ZBASE_PHP_COMMAND', 'php'); $packages = zbase()->packages(); if (!empty($packages)) { foreach ($packages as $packageName) { $zbase = zbase_package($packageName); if ($zbase instanceof Interfaces\ClearCommandInterface) { $this->info($this->signature . '.pre - ' . $packageName); $zbase->clearCommand($phpCommand, ['clear.pre' => true, 'command' => $this]); } } } echo shell_exec($phpCommand . ' artisan clear-compiled'); echo shell_exec($phpCommand . ' artisan cache:clear'); echo shell_exec($phpCommand . ' artisan view:clear'); echo shell_exec($phpCommand . ' artisan config:clear'); echo shell_exec($phpCommand . ' artisan route:clear'); \File::cleanDirectory(zbase_storage_path('tmp/images')); \File::cleanDirectory(zbase_storage_path(zbase_tag() . '_tmp/images')); $commands = []; // zbase()->commands('clear'); if (!empty($commands)) { foreach ($commands as $command) { if ($command instanceof \Closure) { $command(); } else { echo shell_exec($phpCommand . ' artisan ' . $command); } } } if (!empty($packages)) { foreach ($packages as $packageName) { $zbase = zbase_package($packageName); if ($zbase instanceof Interfaces\ClearCommandInterface) { $this->info($this->signature . '.post - ' . $packageName); $zbase->clearCommand($phpCommand, ['clear.post' => true, 'command' => $this]); } } } }
/** * 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); } }
/** * Set the value of the dot-notated key * @see https://laravel.com/docs/5.2/configuration * * @param string $key * @param mixed $value */ function zbase_config_set($key, $value) { $k = zbase_tag() . '.' . $key; app()['config'][$k] = $value; }
/** * Return the File Upload Folder * * @return string */ public function postFileUploadFolder($tmp = false) { if (method_exists($this, 'fileUploadFolder')) { return $this->fileUploadFolder($tmp); } return zbase_storage_path() . '/' . zbase_tag() . '/' . $this->postTableName() . '/' . $this->postId() . '/'; }
/** * Return the Folder Path * @return string */ public function folder() { $path = zbase_storage_path() . '/' . zbase_tag() . '/' . static::$nodeNamePrefix . '/'; if (!empty($this->node_id)) { $path .= $this->node_id . '/'; } return $path; }
/** * 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 Zbase Object * @return Zbase */ function zbase() { return app(zbase_tag()); }
/** * Return the Main Template Layout * * The main template configuration: * view.templates.front.package = The package to use * view.templates.front.theme = The theme to use * view.templates.$tag.front.package = Tag a package to use * view.templates.$tag.front.theme = Tag a package to use * * @param string $tag * @param string $tpl The template file to use * @return string */ function zbase_view_template_layout($tag = null, $tpl = 'layout', $section = null) { $section = is_null($section) ? zbase_section() : $section; $package = zbase_view_template_package($tag); $theme = zbase_view_template_theme($tag); $viewFile = $package . '::templates.' . $section . '.' . $theme . '.' . $tpl; // dd('Section: ' . $section, 'Package: ' . $package, 'Theme: ' . $theme); if (\View::exists($viewFile)) { return $viewFile; } return zbase_tag() . '::templates.' . $section . '.default.' . $tpl; }
public function boot() { parent::boot(); $this->loadViewsFrom(__DIR__ . '/../resources/views', zbase_tag()); $this->loadViewsFrom(__DIR__ . '/../modules', zbase_tag() . 'modules'); if (!zbase_is_testing()) { $this->mergeConfigFrom(__DIR__ . '/../config/config.php', zbase_tag()); $packages = zbase()->packages(); if (!empty($packages)) { foreach ($packages as $packageName) { $packagePath = zbase_package($packageName)->path(); $this->loadViewsFrom($packagePath . 'modules', $packageName . 'modules'); if (zbase_file_exists($packagePath . 'resources/views')) { $this->loadViewsFrom($packagePath . 'resources/views', $packageName); } if (zbase_file_exists($packagePath . 'resources/assets')) { $this->publishes([$packagePath . 'resources/assets' => zbase_public_path(zbase_path_asset($packageName))], 'public'); } if (zbase_file_exists($packagePath . '/Http/Controllers/Laravel/routes.php')) { require $packagePath . '/Http/Controllers/Laravel/routes.php'; } } } $this->app['config'][zbase_tag()] = array_replace_recursive($this->app['config'][zbase_tag()], zbase()->getPackagesMergedConfigs()); } else { $this->loadViewsFrom(__DIR__ . '/../tests/resources/views', zbase_tag() . 'test'); copy(__DIR__ . '/../config/entities/user.php', __DIR__ . '/../tests/config/entities/user.php'); $this->mergeConfigFrom(__DIR__ . '/../tests/config/config.php', zbase_tag()); } $this->publishes([__DIR__ . '/../resources/assets' => zbase_public_path(zbase_path_asset())], 'public'); $this->publishes([__DIR__ . '/../database/migrations' => base_path('database/migrations'), __DIR__ . '/../database/seeds' => base_path('database/seeds'), __DIR__ . '/../database/factories' => base_path('database/factories')], 'migrations'); $this->app['config']['database.connections.mysql.prefix'] = zbase_db_prefix(); $this->app['config']['auth.providers.users.model'] = get_class(zbase_entity('user')); $this->app['config']['auth.passwords.users.table'] = zbase_config_get('entity.user_tokens.table.name'); $this->app['config']['auth.passwords.users.email'] = zbase_view_file_contents('auth.password.email.password'); require __DIR__ . '/Http/Controllers/Laravel/routes.php'; zbase()->prepareWidgets(); /** * Validator to check for account password * @TODO should be placed somewhere else other than here, and just call */ \Validator::extend('accountPassword', function ($attribute, $value, $parameters, $validator) { if (zbase_auth_has()) { $user = zbase_auth_user(); if (zbase_bcrypt_check($value, $user->password)) { return true; } } return false; }); \Validator::replacer('accountPassword', function ($message, $attribute, $rule, $parameters) { return _zt('Account password don\'t match.'); }); /** * */ \Validator::extend('passwordStrengthCheck', function ($attribute, $value, $parameters, $validator) { // if(!preg_match("#[0-9]+#", $value)) // { // //$errors[] = "Password must include at least one number!"; // return false; // } // // if(!preg_match("#[a-zA-Z]+#", $value)) // { // //$errors[] = "Password must include at least one letter!"; // return false; // } return true; }); \Validator::replacer('passwordStrengthCheck', function ($message, $attribute, $rule, $parameters) { return _zt('New password is too weak.'); }); // dd(zbase_config_get('email.account-noreply.email')); // dd(\Zbase\Utility\Service\Flickr::findByTags(['heavy equipment','dozers','loader'])); }
/** * Session namespacing * * @param string $key * @return string */ function zbase_session_name($key) { return zbase_tag() . '_' . $key; }
/** * Set template defaults * */ protected function _setDefaults() { $this->setPageTitle(zbase_config_get('view.default.title.title', null)); zbase_view_meta_description(zbase_config_get('view.default.description', 'Zbase - aims to provide an effortless module to the world, regardless of the framework!')); zbase_view_meta_keywords(zbase_config_get('view.default.keywords', 'laravel, zend framework, php, framework, module')); $this->placeholders['body_class'][zbase_tag()] = zbase_tag(); $navMain = zbase_config_get('nav.' . zbase_section()); if (!empty($navMain)) { foreach ($navMain as $group => $navs) { if (!empty($navs)) { $counter = 0; foreach ($navs as $id => $nav) { if (empty($nav['id'])) { $nav['id'] = $id; } if (!isset($nav['position'])) { $nav['position'] = $counter++; } $this->add(self::NAVIGATION, $nav, $group); } } } } }
/** * Check if there is an alert for $type * * @param type $type * @return boolean */ function zbase_alerts_has($type = null) { $tag = zbase_tag() . '_alert_' . $type . '_pool'; $session = zbase_session(); return $session->has($tag); }
/** * Return the Asset base path * @return string */ function zbase_path_asset($path = null, $absolute = false) { return (!empty($absolute) ? zbase_url_root() : null) . '/' . zbase_tag() . '/assets/' . $path; }
<?php $hasAuth = zbase_auth_has(); $section = 'backend'; $prefix = zbase_tag(); $modules = zbase()->modules(); $isMobile = zbase_is_mobile(); $isMobileTablet = zbase_is_mobileTablet(); $routeProviders = []; $controllers = []; $mainControllerString = []; $mobileIndex = zbase_is_mobile() ? 'mobile.' : ''; foreach ($modules as $module) { if (!$module->isEnable()) { continue; } $moduleRouteProviders = $module->_v('angular.mobile.' . $section . '.routeProvider', $module->_v('angular.' . $section . '.routeProvider', [])); if (!empty($moduleRouteProviders)) { foreach ($moduleRouteProviders as $moduleRouteProvider) { $auth = zbase_data_get($moduleRouteProvider, 'auth', true); if (empty($auth) && !empty($hasAuth)) { continue; } if (!empty($auth) && empty($hasAuth)) { continue; } $url = zbase_data_get($moduleRouteProvider, 'url', null); $templateUrl = zbase_data_get($moduleRouteProvider, 'templateUrl', null); $controller = zbase_data_get($moduleRouteProvider, 'controller', null); if (!empty($url) && !empty($templateUrl) && !empty($controller)) { $routeProviders[] = '$routeProvider.when(\'' . $url . '\', {templateUrl : \'' . $templateUrl . '?at=1\',controller : \'' . $controller . '\', reloadOnSearch: false});';
/** * 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); } }
/** * Prefix all request name * * @param string $key * @return string */ function zbase_request_name($key) { return zbase_tag() . '_' . $key; }