public function boot() { if (zbase_file_exists(__DIR__ . '/../resources/views')) { $this->loadViewsFrom(__DIR__ . '/../resources/views', packagename_tag()); } if (zbase_file_exists(__DIR__ . '/../resources/assets')) { $this->publishes([__DIR__ . '/../resources/assets' => zbase_public_path(zbase_path_asset(packagename_tag()))], 'public'); } if (zbase_file_exists(__DIR__ . '/Http/Controllers/Laravel/routes.php')) { require __DIR__ . '/Http/Controllers/Laravel/routes.php'; } }
/** * 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); } }
/** * Return CSV Contents * * @param string $filename The filename * @return array */ function zbase_get_csv($filename) { if (zbase_file_exists($filename)) { $fh = fopen($filename, "r"); $csvs = []; while (!feof($fh)) { $csvs[] = fgetcsv($fh); } fclose($fh); return $csvs; } return 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 { $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); } }
/** * Return widgets by Index and IndexName * @param string $index * @param string $indexName */ public function getWidgets($index, $indexName) { $section = zbase_section(); $hasSection = $this->_v('widgets.' . $section, false); if (!empty($hasSection)) { $byAction = $this->_v('widgets.' . $section . '.controller.' . $index, []); if (!empty($byAction)) { $widgets = $this->_v('widgets.' . $section . '.controller.' . $index . '.' . $indexName, []); } else { $widgets = $this->_v('widgets.' . $section . '.controller.' . $indexName, []); } /** * If widgets are for this action, * then let;s look at if there is a "default" action to do. * * On the front/public pages, we have links like: node/action/nodeId * but if there are no widgets on the given action, * probably, the given action is the slug-name of an entity * like: * node/node-slug-id * nodes/category-slug-id * so if the module has a "default" index, then we will load that default widget */ if (empty($widgets)) { $widgets = $this->_v('widgets.' . $section . '.controller.' . $index . '.default', $this->_v('widgets.' . $section . '.controller.default', [])); } } else { $widgets = $this->_v('widgets.controller.' . $indexName, []); } if (is_array($widgets)) { foreach ($widgets as $name => $path) { if ($path instanceof \Closure) { $path(); continue; } if (is_string($path) && zbase_file_exists($path)) { $config = (require $path); } if (!empty($config) && is_array($config)) { if (empty($config['id'])) { $config['id'] = $name; } $widget = zbase_widget(['id' => $name, 'config' => $config]); } if (is_null($path)) { $widget = zbase()->widget($name, [], true); } if ($widget instanceof \Zbase\Widgets\WidgetInterface) { $widget->setModule($this); $widgets[$name] = $widget; } } return $widgets; } return $widgets; }
/** * Add a module * Module will be created only f they are called. * @param string $path Path to module folder with a module.php returning an array * @retur Zbase */ public function addModule($name, $path) { if (zbase_file_exists($path . '/module.php')) { $config = (require zbase_directory_separator_fix($path . '/module.php')); $name = !empty($config['id']) ? $config['id'] : null; if (empty($name)) { throw new Exceptions\ConfigNotFoundException('Module configuration ID not found.'); } if (!empty($name)) { $enable = zbase_data_get($config, 'enable'); if (empty($this->modules[$name]) && $enable) { $config['path'] = $path; $this->modules[$name] = $config; } return $this; } } // throw new Exceptions\ConfigNotFoundException('Module ' . $path . ' folder or ' . zbase_directory_separator_fix($path . '/module.ph') . ' not found.'); }
/** * Post Upload a new File * @param type $fileIndex */ public function postUploadFile($fileIndex = 'file', $caption = null) { try { if (!$this->postFileEnabled()) { throw new \Zbase\Exceptions\ConfigNotFoundException('Uploading is disabled for ' . $this->postTableName()); } $defaultImageFormat = zbase_config_get('post.files.image.format', 'png'); $folder = $this->postFileUploadFolder(); zbase_directory_check($folder, true); /** * Check if we have a URL given * @TODO save image that are from remote URL */ if (preg_match('/http\\:/', $fileIndex) || preg_match('/https\\:/', $fileIndex)) { return; } if (!empty($_FILES[$fileIndex]['name'])) { $filename = zbase_file_name_from_file($_FILES[$fileIndex]['name'], time(), true); $uploadedFile = zbase_file_upload_image($fileIndex, $folder, $filename, $defaultImageFormat); } if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) { /** * No Table, let's use the option column * to save the image link */ if (!$this->postFileHasTable()) { $file = new \stdClass(); } if (!empty($file)) { $file->is_primary = 0; $file->status = 2; $file->mimetype = zbase_file_mime_type($uploadedFile); $file->size = zbase_file_size($uploadedFile); $file->filename = basename($uploadedFile); $file->post_id = $this->postId(); $file->caption = $caption; return $this->postFileAdd($file); } } } catch (\Zbase\Exceptions\RuntimeException $e) { zbase_exception_throw($e); return false; } }
/** * Receive the File/Image * * @param \Zbase\Entity\Laravel\Entity $parentObject The Parent */ public function receiveFile(\Zbase\Entity\Laravel\Entity $parentObject) { try { $index = 'file'; $entityName = $this->entityName; $defaultImageFormat = zbase_config_get('node.files.image.format', 'png'); $folder = zbase_storage_path() . '/' . zbase_tag() . '/' . $this->actionUrlRouteName() . '/' . $parentObject->id() . '/'; zbase_directory_check($folder, true); $nodeFileObject = zbase_entity($entityName, [], true); $nodeFiles = $parentObject->childrenFiles(); 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 { $this->is_primary = empty($nodeFiles) ? 1 : 0; $this->status = 2; $this->mimetype = null; $this->size = null; $this->filename = null; $this->url = $index; $this->{$this->parentObjectIndexId} = $parentObject->id(); $this->user_id = zbase_auth_has() ? zbase_auth_user()->id() : null; $this->save(); return true; } } 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)) { $this->is_primary = empty($nodeFiles) ? 1 : 0; $this->status = 2; $this->user_id = zbase_auth_has() ? zbase_auth_user()->id() : null; $this->mimetype = zbase_file_mime_type($uploadedFile); $this->size = zbase_file_size($uploadedFile); $this->filename = basename($uploadedFile); $this->{$this->parentObjectIndexId} = $parentObject->id(); if (empty($nodeFiles)) { $parentObject->image = $this->filename; $parentObject->save(); } $this->save(); return true; } } catch (\Zbase\Exceptions\RuntimeException $e) { if (zbase_is_dev()) { dd($e); } zbase_abort(500); } return 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 uploadProfileImage($index = 'file') { try { $folder = $this->profileFolder(); zbase_directory_check($folder, true); $filename = md5($this->alphaId() . time()); $uploadedFile = zbase_file_upload_image($index, $folder, $filename, zbase_config_get('node.files.image.format', 'png')); if (!empty($uploadedFile) && zbase_file_exists($uploadedFile)) { if (file_exists($folder . $this->avatar)) { unlink($folder . $this->avatar); } return basename($uploadedFile); } } catch (\Zbase\Exceptions\RuntimeException $e) { zbase_exception_throw($e); } }
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'])); }
/** * eturns the size of the image file in bytes or false if image instance is not created from a file. * @param string $file The File to question * @return boolean|integer */ function zbase_file_size($file) { if (zbase_file_exists($file)) { if (exif_imagetype($file)) { if (class_exists('\\Image')) { return \Image::make($file)->filesize(); } return filesize($file); } } return null; }
/** * Return the Country States * @param string $country ISO2 CountryName * @return array [ISO2 => StateName] */ public function getCountryStates($country) { $file = zbase_path_library('Geo/' . strtoupper($country) . '/states.php'); if (zbase_file_exists($file)) { return require $file; } }